UVALive - 3882:And Then There Was One
约瑟夫环
f[i]表示有i个人先处理第k个人,最后被处理的人是谁
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#define MAXN 10005
using namespace std;
int f[MAXN];
int n,m,k;
int main()
{
while(){
scanf("%d%d%d",&n,&k,&m);
if(!n)break;
for(int i=;i<=n;i++){
f[i]=(f[i-]+k)%i;
}
printf("%d\n",((m-k+f[n])%n+n)%n+);
}
return ;
}
UVALive - 3882:And Then There Was One的更多相关文章
- UVA 1394 And Then There Was One / Gym 101415A And Then There Was One / UVAlive 3882 And Then There Was One / POJ 3517 And Then There Was One / Aizu 1275 And Then There Was One (动态规划,思维题)
UVA 1394 And Then There Was One / Gym 101415A And Then There Was One / UVAlive 3882 And Then There W ...
- UVALive 3882 - And Then There Was One【约瑟夫问题】
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- UVALive - 7831 :ACM Tax (主席树求树路径上中位数:LCA+主席树)
题意:给定一棵带权树,Q次询问,每次询问路径上的中位数. 思路:中位数分边数奇偶考虑,当当边数为num=奇时,结果就算路径第num/2+1大,用主席树做即可... (做了几道比较难的主席树,都wa了. ...
- UVALive 6255:Kingdoms(状压DFS)
题目链接 题意 给出n个王国和n*n的矩阵,mp[i][j] 代表第 i 个王国欠第 j 个王国 mp[i][j] 块钱.如果当前的王国处于负债状态,那么这个王国就会被消除,和它相连的王国的债务都会被 ...
- UVALive - 4097:Yungom(逼近 贪心)(DP)
pro:有D个字母,每个字母有自己的权值,现状需要用它们拼出N个单词,使得这些单词互相不为另外一个的前缀. 且单词的权值和最小.D<=200; N<=200; sol:如果建立字典树,那个 ...
- UVALive - 3026:Period
用KMP里面的next数组即可,原理就是next数组的原理 #include<cstdio> #include<cstdlib> #include<algorithm&g ...
- UVALive - 3942:Remember the Word
发现字典里面的单词数目多且长度短,可以用字典树保存 f[i]表示s[i~L]的分割方式,则有f[i]=∑f[i+len(word[j])] 其中word[j]为s[i~L]的前缀 注意字典树又叫前 ...
- UVALive - 3938:"Ray, Pass me the dishes!"
优美的线段树 #include<cstdio> #include<cstdlib> #include<algorithm> #include<cstring& ...
- UVALive - 3027:Corporative Network
加权并查集 #include<cstdio> #include<cstdlib> #include<algorithm> #include<cstring&g ...
随机推荐
- c语言一,二数组
一.PTA实验作业 题目1:7-4 简化的插入排序 1. 本题PTA提交列表 2. 设计思路 1.定义整形变量N,temp,i. 2.输入N 3.通过for(i=1;i<=N;i++)的循环语句 ...
- alpha-咸鱼冲刺day6
一,合照 emmmmm.自然还是没有的. 二,项目燃尽图 三,项目进展 !!!QAQ可以做到跟数据库交互了!!!!先来撒花花!(然后继续甲板) (然后就没有进展了.翻车+1s) 四,问题困难 数据库交 ...
- C语言第五次博客作业
一.PTA实验作业 题目1:6-6 使用函数输出水仙花数 1. 本题PTA提交列表 2. 设计思路 (1) 首先先定义narcissistic函数. (2)定义四个整形变量n,a,d,cnt,sum, ...
- io多路复用(二)
服务端 import socket sk1 = socket.socket() sk1.bind(('127.0.0.1',8001,)) sk1.listen() inputs = [sk1,] i ...
- 使用Putty连接Amazon EC2 Instance
Amazon的EC2中,默认是不允许使用用户名和密码直接连接Instance的,而是通过AWS (Amazon Web Service)提供的证书.在第一次使用EC2的时候,AWS会要求你创建一个证书 ...
- nyoj 擅长排列的小名II
擅长排列的小明 II 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 小明十分聪明,而且十分擅长排列计算. 有一天小明心血来潮想考考你,他给了你一个 ...
- JAVA_SE基础——37.main方法的详解
主函数 大家都会写吧. 大家一直都不知道为何这样设计,这样设计有什么好处呢? 白话解释: main函数的修饰符是public: 公共的 为何不用private 等等的修饰符 而规定只用public呢? ...
- jsMath对象
Math对象: abs.用来求绝对值. ceil:用来向上取整. floor:用来向下取整. round:用来四舍五入取近似值. sqrt:用来开方. pow:括号内有2位参数.如pow(2,5)表示 ...
- WPF 自定义TextBox带水印控件,可设置圆角
一.简单设置水印TextBox控件,废话不多说看代码: <TextBox TextWrapping="Wrap" Margin="10" Height=& ...
- HTTP协议扫盲(八 )响应报文之 Transfer-Encoding=chunked方式
一.什么是chunked编码? 分块传输编码(Chunked transfer encoding)是只在HTTP协议1.1版本(HTTP/1.1)中提供的一种数据传送机制.以往HTTP的应答中数据是整 ...