CSP认证201712-2-游戏-(Java)100分 游戏 试题编号: 201712-2 试题名称: 游戏 时间限制: 1.0s 内存限制: 256.0MB 问题描述 有n个小朋友围成一圈玩游戏,小朋友从1至n编号,2号小朋友坐在1号小朋友的顺时针方向,3号小朋友坐在2号小朋友的顺时针方向,……,1号小朋友坐在n号小朋友的顺时针方向。 游戏开始...
举个栗子:n k = 5 2 当计数值为7时,这个位置已经赋值为0,因此keng数目加一,然后判断d+keng 由于keng的数目就是跳过的位置数目,所以满足d+keng就是真实位置 #include<bits/stdc++.h>usingnamespacestd;inta[1005];intmain(){intn,k;scanf("%d%d",&n,&k);for(inti=0;i<n;i++){ a[i]=1; }in...
2、intisK(int x);判断输入的数x是否满足条件,满足则返回1,否则返回0; 3、while(Sum>1):剩余小朋友数>=2,则一直执行。 (1),第一个while作用:跳过已淘汰的小朋友。因为通过ChildFlag来存储轮至第i个小朋友报数,应先判断flag【ChildFlag】是否等于0,即是否淘汰,通过while()语句跳过连续的已淘汰的小朋友。
include <iostream>#include <queue>using namespace std;int main(){queue<int> q;int n, k;scanf("%d%d", &n, &k);for (int i = 1; i <= n; ++i){q.push(i);}while (q.size() > 1){for (int i = 0; i < k - 1; ++i){int front = q.front();q.pop();q....
if(TAG==2&&isalpha(x[0])) x=to_string_x(mWek[x]);//是day of week英文缩写,转换为数字 45 if(x.size()==1) x="0"+x;//添加0 46 vret.push_back(x); 47 } 48 else//连续值 49 { 50 string L=x.substr(0,fdx),R=x.substr(fdx+1,x.size()-fdx-1); ...
[CCF CSP]201712-2 游戏 约瑟夫环问题,问最后一个剩下的是谁。由于末位是4也要淘汰,所以只可模拟得到结果 #include<bits/stdc++.h> using namespace std; const int N = 1005; const int INF=0x3f3f3f3f; int a[N]; int main() { ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); ...
1 //CCF CSP 201712-2 游戏 2 #include <iostream> 3 #include <algorithm> 4 #include <cstring> 5 using namespace std; 6 int n,k,t,sum,st,flag; 7 int a[1005]; 8 int b[1005]; 9 int main() 10 { 11 while(cin>>n>>k){ 12 memset(b,0,sizeof(b)); 13 for(int i=1;i<...