跳到正文

算法·理论

AC 团队 附属出题团 CSP复赛模拟 官方题解

huangzhiyuanhzy约 4 分钟
原文

这是 2025年10月12日 存档的第 1 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

发布
2025年10月12日
收录
2025年12月12日
更新
2026年11月18日
篇幅
约 4 分钟
获赞
1

版本

  1. v2当前
  2. v1

赛题链接

T1-turtle

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,t[70],sum,v=1,type=1;
signed main(){
	freopen("turtle.in","r",stdin);
	freopen("turtle.out","w",stdout);
	cin>>n;
	for(int i=1;i<=n;i++){
		int op;
		cin>>t[i]>>op;
		if(op==1){
			if(type==1){
				sum+=v*(t[i]-t[i-1]);
			}
			else{
				sum-=v*(t[i]-t[i-1]);
			}
			v*=2;
		}
		else if(op==2){
			if(type==1){
				sum+=v*(t[i]-t[i-1]);
				type=2;
			}
			else{
				sum-=v*(t[i]-t[i-1]);
				type=1;
			}
		}
		else{
			if(type==1){
				sum+=v*(t[i]-t[i-1]);
			}
			else{
				sum-=v*(t[i]-t[i-1]);
			}
			cout<<abs(sum);
			return 0;
		}
	}
	return 0;
}

T2-date

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
int t,date[13]={0,31,0,31,30,31,30,31,31,30,31,30,31};
int p(int y,int m){
	if(m==2){
		if((y%4==0&&y%100!=0)||y%400==0){
			return 29;
		}
		else{
			return 28;
		}
	}
	return date[m];
}
signed main(){
	freopen("date.in","r",stdin);
	freopen("date.out","w",stdout);
	cin>>t;
	while(t--){
		int sy,sm,sd,my,mm,md,ey,em,ed;
		char c;
		cin>>sy>>c>>sm>>c>>sd;
		cin>>my>>c>>mm>>c>>md;
		ey=sy+my;
		em=sm+mm;
		ed=sd+md;
		while(em>12){
			em-=12;
			ey++;
		}
		while(ed>p(ey,em)){
			ed-=p(ey,em);
			em++;
			if(em==13){
				em=1;
				ey++;
			}
		}
		if(ey<10){
			cout<<0<<0<<0<<ey<<"-";
		}
		else if(ey<100){
			cout<<0<<0<<ey<<"-";
		}
		else if(ey<1000){
			cout<<0<<ey<<"-";
		}
		else{
			cout<<ey<<"-";
		}
		if(em<10){
			cout<<0<<em<<"-";
		}
		else{
			cout<<em<<"-";
		}
		if(ed<10){
			cout<<0<<ed<<endl;
		}
		else{
			cout<<ed<<endl;
		}
	}
	return 0;
}

T3-game

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
int t,num[1000010];
signed main(){
	freopen("game.in","r",stdin);
	freopen("game.out","w",stdout);
	cin>>t;
	for(int i=1;i<1000010;i++){
		int maxnum=0,minnum=9;
		for(int tmp=i;tmp>=1;tmp/=10){
			maxnum=max(maxnum,tmp%10);
			if(tmp%10!=0){
				minnum=min(minnum,tmp%10);
			}
		}
		num[i]=(!num[i-minnum])||(!num[i-maxnum]);
	}
	while(t--){
		int n;
		cin>>n;
		if(num[n]==0){
			cout<<"NO"<<endl;
		}
		else{
			cout<<"YES"<<endl;
		}
	}
	return 0;
}