例如:N = 3,K = 2。2号先出列,然后是1号,最后剩下的是3号。
Input
2个数N和K,表示N个人,数到K出列。(2 <= N, K <= 10^6)
Output
最后剩下的人的编号
Input示例
3 2
Output示例
3
/*
* @Author: 王文宇
* @Date: 2017-10-23 06:22:15
* @Last Modified by: 王文宇
* @Last Modified time: 2017-10-23 14:55:40
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n,k;
const int maxn = 1e6+7;
int f[maxn];
int main(int argc, char const *argv[])
{
scanf("%d%d",&n,&k);
f[1]=0;
for(int i=2;i<=n;i++)
{
f[i]=(f[i-1]+k)%i;
}
printf("%d\n",f[n]+1);
return 0;
}
2万+



被折叠的 条评论
为什么被折叠?



