分数 $300pts$ ,排名第四十三(代码源C队)
预计分数:$100pts$
实际得分:$100pts$ (✌)
考试时思路:模拟
考试时代码:
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=3e4+5;
int a[N];
signed main(){
int t;
cin>>t;
while(t--){
int n,k;
cin>>n>>k;
for(int i=1;i<=n-1;i++){
cin>>a[i];
}
int wz=1,f=0;
while(wz<n){
if(wz==k){
f=1;
break;
}
wz+=a[wz];
}
if(wz==k){
f=1;
}
if(f==1){
cout<<"YES"<<endl;
}
else{
cout<<"NO"<<endl;
}
}
return 0;
}
预计分数:$100pts$
实际得分:$100pts$ (嘻嘻)
考试时思路:双重遍历,用$i$遍历蜗蜗攻击值,用$j$遍历蜗蜗防御值,从而计算出蜗蜗的血量,进而求出最小值
考试时代码:
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
int hw,aw,dw;
cin>>hw>>aw>>dw;
int hm,am,dm;
cin>>hm>>am>>dm;
int h,a,d;
cin>>h>>a>>d;
long long minn=1e18;
for(int i=0;i<=1000;i++){
for(int j=0;j<=1000;j++){
int aww=aw+i;
int dww=dw+j;
int wdg=max(aww-dm,0LL);
if(wdg==0){
continue;
}
int bs=(hm+wdg-1)/wdg;
int gdw=max(am-dww,0LL);
int out=bs*gdw+1;
int k=max(out-hw,0LL);
int sum=i*a+j*d+k*h;
minn=min(minn,sum);
}
}
cout<<minn<<endl;
return 0;
}
预计分数:$0pts$
实际得分:$0pts$ (不嘻嘻)
考试时思路:没有思路
考试时代码:
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+5;
long long a[N];
signed main(){
int n,x,y;
cin>>n>>x>>y;
for(int i=1;i<=n;i++){
cin>>a[i];
int xx=(a[i]+x-1)/x;
int yy=(a[i]+y-1)/y;
int lx=xx*y;
int ly=yy*x;
if(lx==ly){
cout<<"Both"<<endl;
}
else if(lx<ly){
cout<<"Wowo"<<endl;
}
else{
cout<<"Momo"<<endl;
}
}
return 0;
}
预计分数:$80pts$
实际得分:$100pts$
考试时思路:$gcd+d$p
考试时代码:
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=3e2+5;
int l[N],c[N];
map<int,int> dp;
signed main(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>l[i];
}
for(int i=1;i<=n;i++){
cin>>c[i];
}
int gcdd=l[1];
for(int i=2;i<=n;i++){
gcdd=__gcd(gcdd,l[i]);
}
if(gcdd!=1){
cout<<-1;
return 0;
}
dp[0]=0;
for(int i=1;i<=n;i++){
auto a=dp;
for(const auto& j:a){
int x=j.first;
int y=j.second;
int ngccd=__gcd(x,l[i]);
int ny=y+c[i];
if(dp.find(ngccd)==dp.end()||ny<dp[ngccd]){
dp[ngccd]=ny;
}
}
}
cout<<dp[1];
return 0;
}
预计分数:$5pts$
实际得分:$0pts$
考试时思路:骗子任务的分
考试时代码:
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
string s;
cin>>s;
int cnt=0;
for(int i=0;i<s.size();i++){
if(s[i]=='1'){
cnt++;
}
}
for(int i=0;i<=n;i++){
if(i==cnt){
cout<<cnt+1<<" ";
}
else{
cout<<-1<<" ";
}
}
cout<<endl;
}
return 0;
}
正解代码:
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=3e4+5;
int a[N];
signed main(){
int t;
cin>>t;
while(t--){
int n,k;
cin>>n>>k;
for(int i=1;i<=n-1;i++){
cin>>a[i];
}
int wz=1,f=0;
while(wz<n){
if(wz==k){
f=1;
break;
}
wz+=a[wz];
}
if(wz==k){
f=1;
}
if(f==1){
cout<<"YES"<<endl;
}
else{
cout<<"NO"<<endl;
}
}
return 0;
}
正解代码:
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
int hw,aw,dw;
cin>>hw>>aw>>dw;
int hm,am,dm;
cin>>hm>>am>>dm;
int h,a,d;
cin>>h>>a>>d;
long long minn=1e18;
for(int i=0;i<=1000;i++){
for(int j=0;j<=1000;j++){
int aww=aw+i;
int dww=dw+j;
int wdg=max(aww-dm,0LL);
if(wdg==0){
continue;
}
int bs=(hm+wdg-1)/wdg;
int gdw=max(am-dww,0LL);
int out=bs*gdw+1;
int k=max(out-hw,0LL);
int sum=i*a+j*d+k*h;
minn=min(minn,sum);
}
}
cout<<minn<<endl;
return 0;
}
正解代码:
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int a[N];
bool boo(long long mid,long long m,long long x,long long y){
long long t=mid/y+mid/x;
return t>=m;
}
int main(){
int n,x,y;
cin>>n>>x>>y;
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<=n;i++){
long long l=0,r=2e18;
while(l<r){
long long mid=(l+r)/2;
if(boo(mid,a[i],x,y)){
r=mid;
}
else{
l=mid+1;
}
}
if(l%x==0&&l%y==0){
cout<<"Both"<<endl;
}
else if(l%y==0){
cout<<"Wowo"<<endl;
}
else{
cout<<"Momo"<<endl;
}
}
return 0;
}
正解代码:
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=3e2+5;
int l[N],c[N];
map<int,int> dp;
signed main(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>l[i];
}
for(int i=1;i<=n;i++){
cin>>c[i];
}
int gcdd=l[1];
for(int i=2;i<=n;i++){
gcdd=__gcd(gcdd,l[i]);
}
if(gcdd!=1){
cout<<-1;
return 0;
}
dp[0]=0;
for(int i=1;i<=n;i++){
auto a=dp;
for(const auto& j:a){
int x=j.first;
int y=j.second;
int ngccd=__gcd(x,l[i]);
int ny=y+c[i];
if(dp.find(ngccd)==dp.end()||ny<dp[ngccd]){
dp[ngccd]=ny;
}
}
}
cout<<dp[1];
return 0;
}
正解代码:
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e5+5;
int v0[N],v1[N],v01[N];
bool cmp(int a,int b){
return a>b;
}
signed main(){
int t;
cin>>t;
while(t--){
int n;
string s;
cin>>n>>s;
for(int i=1;i<=n;i++){
v0[i]=v1[i]=v01[i]=0;
}
int sz0=0,sz1=0,sz01=0;
int cnt=0,p=0,ans=0,sum1=0;
for(int i=0;i<n;i++){
if(s[i]!='?'){
if(s[i]=='1'){
sum1++;
}
if(cnt){
if(s[p]!=s[i]){
v01[++sz01]=cnt;
ans++;
}
else{
if(s[i]=='0'){
v0[++sz0]=cnt;
}
else{
v1[++sz1]=cnt;
ans+=2;
}
}
cnt=0;
}
else{
if(!i||s[i-1]!=s[i]){
ans++;
}
}
}
else{
if(!cnt){
p=i-1;
}
cnt++;
}
}
sort(v0+1,v0+sz0+1,cmp);
sort(v1+1,v1+sz1+1);
sort(v01+1,v01+sz01+1);
for(int i=1;i<=sz0;i++){
v0[i]+=v0[i-1];
}
for(int i=1;i<=sz1;i++){
v1[i]+=v1[i-1];
}
for(int i=1;i<=sz01;i++){
v01[i]+=v01[i-1];
}
for(int i=0;i<=n;i++){
if(i<sum1||i>v0[sz0]+v1[sz1]+v01[sz01]+sum1){
cout<<-1<<" ";
continue;
}
int sum=0,y=i-sum1;
int x=upper_bound(v1+1,v1+sz1+1,y)-v1-1;
sum-=2*x;
y-=v1[x];
if(x==sz1){
x=upper_bound(v01+1,v01+sz01+1,y)-v01-1;
y-=v01[x];
if(x==sz01){
x=upper_bound(v0+1,v0+sz0+1,y)-v0-1;
y-=v0[x];
if(y>0){
sum+=2;
}
sum+=2*x;
}
}
cout<<ans+sum<<" ";
}
cout<<endl;
}
return 0;
}