标签:ace namespace and else code return win amp pre
二维or一维前缀和都可以,我是二维。哈哈哈,刚好借助这道题练了一下对拍,顺便把对拍的程序也挂上。
数据制作器
#include<bits/stdc++.h> #include<ctime> using namespace std; int main(){ freopen("text.txt","w",stdout); srand(time(0)); int t=rand()%10+1,k=rand()%20+1; printf("%d %d\n",t,k); for(int i=1;i<=t;++i){ int n,m=rand()%10; n=m+rand()%10; printf("%d %d\n",n,m); } return 0; }
对拍器
#include<bits/stdc++.h> #include<windows.h> #include<ctime> using namespace std; int main(){ for(int i=1;i<=100;++i){ system("maker.exe"); system("brute.exe"); system("std.exe"); if(system("fc s.out b.out")){ puts("GG"); exit(0); } printf("\npassed %d\n",i); Sleep(1000); } return 0; }
暴力
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll C(ll n,ll m){ ll ret=1; for(ll i=n;i>=n-m+1;--i){ ret*=i; } for(ll i=1;i<=m;++i){ ret/=i; } return ret; } int main(){ freopen("text.txt","r",stdin); freopen("b.out","w",stdout); ll T,k; scanf("%d%d",&T,&k); while(T--){ ll n,m,ans=0; scanf("%d%d",&n,&m); for(ll i=0;i<=n;++i){ for(ll j=0;j<=min(i,m);++j){ if(C(i,j)%k==0)++ans; } } printf("%d\n",ans); } return 0; }
std
#include<bits/stdc++.h> using namespace std; const int maxn=2010; int a[maxn][maxn],f[maxn][maxn]; int main(){ freopen("text.txt","r",stdin); freopen("s.out","w",stdout); int T,k; scanf("%d%d",&T,&k); for(int i=0;i<=2000;++i){ for(int j=0;j<=i;++j){ if(j==0)a[i][j]=1; else a[i][j]=a[i-1][j]+a[i-1][j-1]; if(a[i][j]%k==0)f[i][j]=1; a[i][j]%=k; } } for(int i=0;i<=2000;++i){ for(int j=0;j<=2000;++j){ if(j!=0)f[i][j]+=f[i][j-1]; if(i!=0)f[i][j]+=f[i-1][j]; if(i!=0&&j!=0)f[i][j]-=f[i-1][j-1]; } } while(T--){ int n,m; scanf("%d%d",&n,&m); printf("%d\n",f[n][m]); } return 0; }
标签:ace namespace and else code return win amp pre
原文地址:https://www.cnblogs.com/Dream-Runner/p/9451852.html