LA 3882 And Then There Was One[约瑟夫问题的变形]
And Then There Was One



Sample Input
Sample Output
//设f[i]为(原约瑟夫问题)第i次要删除的标号
#include<cstdio>
using namespace std;
const int N=1e4+;
int n,m,k,f[N];
int main(){
while(scanf("%d%d%d",&n,&k,&m)==&&n){
//f[1]=0;
//for(int i=2;i<=n;i++) f[i]=(f[i-1]+k)%i;
//int ans=(m-k+f[n]+1)%n;
int s=;
for(int i=;i<=n;i++) s=(s+k)%i;
int ans=(m-k+s+)%n;//这3句话来源于上面
if(ans<=) ans+=n;
printf("%d\n",ans);
}
return ;
}
LA 3882 And Then There Was One[约瑟夫问题的变形]的更多相关文章
- LA 3882 - And Then There Was One(约瑟夫 递归)
看题传送门 题目大意: N个数排成一圈,第一次删除m,以后每k个数删除一次,求最后一被删除的数. 如果这题用链表或者数组模拟整个过程的话,时间复杂度都将高达O(nk),而n<=10000,k&l ...
- LA 3882 经典约瑟夫环问题的数学递推解法
就是经典约瑟夫环问题的裸题 我一开始一直没理解这个递推是怎么来的,后来终于理解了 假设问题是从n个人编号分别为0...n-1,取第k个, 则第k个人编号为k-1的淘汰,剩下的编号为 0,1,2,3. ...
- LA 3882 And Then There Was One
解题思路:分析要好久,懒得分析了,贴了某大牛的的分析,代码就是我自己写的. N个数排成一圈,第一次删除m,以后每k个数删除一次,求最后一被删除的数. 如果这题用链表或者数组模拟整个过程的话,时间复杂度 ...
- LA 3882
动态规划: 白书上的题,看了好久看不懂刘汝佳的解法: 在网上无意中看到了大神的思路,比较好理解,膜拜! 他的思路是这样的: 设d[i]是n个数按顺时针方向分别从0开始编号,第一次删除0,以后每k个数删 ...
- UVa LA 3882 - And Then There Was One 递推,动态规划 难度: 2
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
- UVa 1394 约瑟夫问题的变形
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA1452|LA4727-----Jump------经典的约瑟夫公式的变形(DP)
本文出自:http://blog.csdn.net/dr5459 题目地址: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&a ...
- LA 4727
Integers 1, 2, 3,..., n are placed on a circle in the increasing order as in the following figure. W ...
- poj 1012 Joseph (约瑟夫问题)
Joseph Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 47657 Accepted: 17949 Descript ...
随机推荐
- Codeforces 629 B. Far Relative’s Problem
B. Far Relative’s Problem time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- 使用Fiddle监听HTTPS网页
HTTPS相对于HTTP增加了安全性,但是仍然不能有效的防止中间人攻击(Man-in-the-MiddleAttack,简称“MITM攻击”) 这就使得Fiddle工具能够有效的监听HTTPS流量 一 ...
- Jenkins里邮件插件触发器配置和Send to Developers到底是什么意思(转)
邮件触发类型介绍(Triggers) By default, the onlytrigger configured is the "Failure" trigger. To ad ...
- apache mina框架
http://blog.csdn.net/ljx8928358/article/details/7759024
- linux基础学习6
daemon 可以理解成为service 两大类: stand_alone:此 daemon 可以自行单独启动服务,加载到内存后就一直占用内存与系统资源:如 www的httpd ,ftp的vsft ...
- Code signing is required for product type Unit Test Bundle in SDK iOS 8.0
I fixed the issue (temporarily) by going to Edit Scheme, then in the Build section, removing my unit ...
- [置顶]
zabbix发送告警
之前使用邮件和短信发送zabbix告警信息,但告警信息无法实时查看或者无法发送,故障无法及时通知运维人员. 后来使用第三方微信接口发送信息,愉快地用了一年多,突然收费了. zabbix告警一直是我的痛 ...
- [置顶]
pycurl检测网站性能,pycurl.*_TIME时间问题
今天使用python+pycurl来检测网站性能,使用curl_obj.getinfo(pycurl.*_TIME)来获取各个阶段运行时间 total_time = curl_obj.getinfo( ...
- HPU 3639--Hawk-and-Chicken【SCC缩点反向建图 && 求传递的最大值】
Hawk-and-Chicken Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- breakpoints && lldb  && chisel 的使用
Breakpoints BreakPoint分类 breakpoint也是有分类的.我这里的文章内大致按使用的方式分为了 Normal Breakpoint,Exception Breakpoint, ...