2020.05.06【NOIP普及组】模拟赛C组32

链接

T1:

找找规律

#include
#include
#include
using namespace std;
int a[10];
int main(){
	freopen("herding.in","r",stdin);
	freopen("herding.out","w",stdout);
	cin>>a[1]>>a[2]>>a[3];
	sort(a+1,a+4);
	if(a[1]+1==a[2]&&a[2]+1==a[3]){
		cout<<0<<endl<<0;
		return 0;
	}
	if(a[1]+2==a[2]||a[2]+2==a[3])cout<<1<<endl;
	else cout<<2<<endl;
	cout<<max(a[2]-a[1],a[3]-a[2])-1;
	return 0;
}

T2:

听别人说:
1 3 5 7 9……
+1 -1 +1 -1 +1……

#include
#include
using namespace std;
int n;
int main(){
	freopen("amp.in","r",stdin);
	freopen("amp.out","w",stdout);
	cin>>n;
	if(n%2==0)cout<<"No solution";	
	else{
		int x=n,ans[50];
		ans[0]=0;
		while(x!=1){
		    if(((x-1)/2+1)%2==1)x=(x+1)/2,ans[++ans[0]]=1;
		    else x=(x-1)/2,ans[++ans[0]]=2;
		}
		cout<<ans[0]<<endl;
		for(int i=ans[0];i>=1;i--)
		cout<<ans[i]<<' ';
	}
	return 0;
}

T3:

BFS

#include
#include
using namespace std;
int m,n,a[100010],f[1001000],b[1001000][2];
int main(){
	freopen("walk.in","r",stdin);
	freopen("walk.out","w",stdout);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	if(a[1]==n){
		cout<<1;
		return 0;
	}
	b[1][1]=a[1];
	b[1][2]=1;
	f[a[1]]=1;
	f[0]=1;
	f[n+1]=1;
	int head=0,tail=1;
	while(head<tail){
		head++;
		int x=b[head][1];
		if(f[a[x]]==0){
			tail++;
			b[tail][1]=a[x];
			b[tail][2]=b[head][2]+1;
			f[a[x]]=1;
			if(a[x]==n){
				cout<<b[tail][2];
				return 0;
			}
		}
		if(f[x+1]==0){
			tail++;
			b[tail][1]=x+1;
			b[tail][2]=b[head][2]+1;
			f[x+1]=1;
			if(x+1==n){
				cout<<b[tail][2];
				return 0;
			}
		}
		if(f[x-1]==0){
			tail++;
			b[tail][1]=x-1;
			b[tail][2]=b[head][2]+1;
			f[x-1]=1;
		}
	}
	return 0;
}

T4:

原题!!!
请参考:2020.02.03【NOIP普及组】模拟赛C组2:count

#include
#include
using namespace std;
int m,n,k,x,y,p;
long long f[101][101][2001],a[101][101];
int main(){
	freopen("count.in","r",stdin);
	freopen("count.out","w",stdout);
	cin>>n>>m>>p;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>a[i][j];
		}
	}
	f[1][1][a[1][1]]=1;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			for(int k=a[i][j];k<=p;k++){
				f[i][j][k]=(f[i][j][k]+f[i-1][j][k-a[i][j]]+f[i][j-1][k-a[i][j]])%1000000007;
			}
		}
	}
	cout<<f[n][m][p];
	return 0;
}

你可能感兴趣的:(比赛)