3 条题解
-
1马睿 (2024sng28) LV 10 @ 2025-1-29 11:29:49
这题本人有数学解法(不是模拟,太麻烦了,而且时间复杂度O(nm),数据大点就超时)
其实还有一个时间复杂度O(m)的解法,但还是不够快
ACcode(最快code)
(复杂度本人也不会算)
#include<bits/stdc++.h> using namespace std; const int N=1e4+5,INF=0x3f3f3f3f; typedef long long LL; LL ceil(LL x,LL y){ return x/y+(x%y!=0); } LL j(LL n,LL q){ LL d=1,end=(q-1)*n; while(d<=end)d = ceil(q*d,q-1); return q*n+1-d; } LL n,q; int main() { cin>>n>>q; cout<<j(n,q); return 0; }
有人能帮我算一下吗?(算出来私聊我)
-
-22023-5-23 17:46:45@
队列直接搞定
int n,m; queue<int>a; int main(){ IOS; cin>>n>>m; for(int i=1;i<=n;i++)//防抄袭,这里实现入队操作 while(a.size()!=1){ for(int i=1;i<m;i++){ a.push(a.front());//将队首放入队尾 a.pop();//弹出队首 } a.pop(); } cout<<a.front(); return 0; }
-
-22022-11-17 15:23:24@
太简单了
#include <iostream> using namespace std; bool a[1005]; int main() { int n,m,cnt=0,i=0,p=0; cin >> n >> m; while(i=i%n+1){ // cout << a[i] << " " << i << " " << cnt << " " << p << endl; if(cnt==n-1){ break; } if(a[i]==false){ p++; } if(p==m){ p=0; a[i]=true; cnt++; } } for(int i = 1; i <= n; i++){ if(a[i]==false){ cout << i; return 0; } } }
- 1
信息
- ID
- 1028
- 时间
- 1000ms
- 内存
- 32MiB
- 难度
- 7
- 标签
- 递交数
- 252
- 已通过
- 63
- 上传者