C题为撒会卡cin呢?
运行超时代码
// Problem: Karashi的生日蛋糕 // Contest: NowCoder // URL: https://ac.nowcoder.com/acm/contest/49244/C // Memory Limit: 524288 MB // Time Limit: 2000 ms // Date: 2022-12-30 19:13:55 // // Powered by CP Editor (https://cpeditor.org) /** * @author : SDTBU_LY * @version : V1.0.0 * @上联 : ac自动机fail树上dfs序建可持久化线段树 * @下联 : 后缀自动机的next指针DAG图上求SG函数 **/ #include<iostream> #include<cstring> #include<algorithm> #include<vector> #define MAXN 1000010 using namespace std; typedef long long ll; int n,k; vector<int> v[MAXN]; int main() { ios::sync_with_stdio(false); cin.tie(0),cout.tie(0); cin >> n >> k; int pos=0; for(int i=1;i<=n;i++) { int num=i; int temp=num/k,d=num%k; for(int j=0;j<=d-1;j++) v[(pos+j)%k].push_back(temp+1); for(int j=d;j<=k-1;j++) v[(pos+j)%k].push_back(temp); pos=(pos+num)%k; //cout << pos << endl; } for(int i=0;i<=k-1;i++) { for(int j=0;j<n;j++) cout << v[i][j] << ' '; cout << endl; } return 0; }
AC代码
// Problem: Karashi的生日蛋糕 // Contest: NowCoder // URL: https://ac.nowcoder.com/acm/contest/49244/C // Memory Limit: 524288 MB // Time Limit: 2000 ms // Date: 2022-12-30 19:13:55 // // Powered by CP Editor (https://cpeditor.org) /** * @author : SDTBU_LY * @version : V1.0.0 * @上联 : ac自动机fail树上dfs序建可持久化线段树 * @下联 : 后缀自动机的next指针DAG图上求SG函数 **/ #include<iostream> #include<cstring> #include<algorithm> #include<vector> #define MAXN 1000010 using namespace std; typedef long long ll; int n,k; vector<int> v[MAXN]; int main() { ios::sync_with_stdio(false); cin.tie(0),cout.tie(0); scanf("%d %d",&n,&k); int pos=0; for(int i=1;i<=n;i++) { int num=i; int temp=num/k,d=num%k; for(int j=0;j<=d-1;j++) v[(pos+j)%k].push_back(temp+1); for(int j=d;j<=k-1;j++) v[(pos+j)%k].push_back(temp); pos=(pos+num)%k; //cout << pos << endl; } for(int i=0;i<=k-1;i++) { for(int j=0;j<n;j++) printf("%d ",v[i][j]); printf("\n"); } return 0; }