POJ-3517-And Then There Was One
来源:互联网 发布:制造业数据采集公司 编辑:程序博客网 时间:2024/05/21 18:01
Uva 题目:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1883
这个题类似于约瑟夫环,但是由于题目数据比较大,所以只能采用递推的做法。
可以通过画图的方法得到转移方程,即dp[n]=(dp[n-1]+k)%n
最后仅仅是需要加上开始的位置偏差即可。
由于k的数值比较大,最后可能出现负数与0的情况,需要特殊处理一下。
代码:
#include<cstdio>#include<cstring>#include<iostream>using namespace std;const int maxn=1e4+10;int dp[maxn];int main(){ int n,k,m; while(scanf("%d%d%d",&n,&k,&m)&&n) {dp[1]=0;for(int i=2;i<=n;i++) dp[i]=(dp[i-1]+k)%i;int ans=(dp[n]+m-k+1)%n;if(ans<=0) ans=ans+n;printf("%d\n",ans); } return 0;}
- POJ 3517 And Then There Was One
- POJ-3517-And Then There Was One
- POJ 3517 And Then There Was One
- POJ 3517 And Then There Was One
- POJ 3157 And Then There Was One
- POJ 3517 And Then There Was One 约瑟夫环
- POJ 3517 And Then There Was One 约瑟夫环
- Poj 3517 And Then There Was One Joseph环问题
- UVA 1394/POJ 3517 And Then There Was One
- And Then There Was One - POJ 3517 递推
- poj 3517 And Then There Was One 约瑟夫问题
- POJ 3517 And Then There Was One(约瑟夫环)
- POJ 3517 And Then There Was One 可能会
- POJ-3517 And Then There Was One (约瑟夫环模板)
- And Then There Was One
- And Then There Was One
- POJ 3157 And Then There Was One【约瑟夫变形】
- POJ 3517 And Then There Was One (递推,约瑟夫问题变形)
- mysql配置文件my.cnf详解[部分]
- C#中的关键字
- ANDROID GETTING STARTED WITH JB
- unbutu linux下安装VMware tools
- 第四章例题4_3和4_4
- POJ-3517-And Then There Was One
- Ant build.xml解析
- 11.2.0.3.1补丁升级学习
- 获取Android源码的简明步骤
- jQuery总结第二天
- Spring的分布式事务,使用或不用XA - 7
- 游戏手柄编程DEMO 基于 VB.NET+API 暂无力反馈
- tomcat虚拟路径的几种配置方法
- WCHAR我不再惧怕了