UVA 1452 八 Jump
Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu
Integers 1, 2, 3,..., n are placed on a circle in the increasing order as in the following figure. We want to construct a sequence from these numbers on a circle. Starting with the number 1, we continually go round by picking out each k-th number and send to a sequence queue until all numbers on the circle are exhausted. This linearly arranged numbers in the queue are called Jump(n, k) sequence where 1n, k.
Let us compute Jump(10, 2) sequence. The first 5 picked numbers are 2, 4, 6, 8, 10 as shown in the following figure. And 3, 7, 1, 9 and 5 will follow. So we get Jump(10, 2) = [2,4,6,8,10,3,7,1,9,5]. In a similar way, we can get easily Jump(13, 3) = [3,6,9,12,2,7,11,4,10,5,1,8,13], Jump(13, 10) = [10,7,5,4,6,9,13,8,3,12,1,11,2] and Jump(10, 19) = [9,10,3,8,1,6,4,5,7,2].
You write a program to print out the last three numbers of Jump(n, k) for n, k given. For example suppose that n = 10, k = 2, then you should print 1, 9 and 5 on the output file. Note that Jump(1, k) = [1].
Input
Your program is to read the input from standard input. The input consists of T test cases. The number of test cases T is given in the first line of the input. Each test case starts with a line containing two integers n and k, where 5n500, 000 and 2k500, 000.
Output
Your program is to write to standard output. Print the last three numbers of Jump(n, k) in the order of the last third, second and the last first. The following shows sample input and output for three test cases.
Sample Input
3
10 2
13 10
30000 54321
#include <stdio.h> int fun(int m,int k,int i){ if(i==)
return (m+k-)%m;
else
return (fun(m-,k,i-)+k)%m; } int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n,k,a,b,c;
scanf("%d %d",&n,&k);
if(k%==)
a=,b=,c=;
if(k%==)
a=,b=,c=;
if(k%==)
a=,b=,c=;
if(k%==)
a=,b=,c=;
if(k%==)
a=,b=,c=;
if(k%==)
a=,b=,c=;
a--,b--,c--;
for(int i=;i<=n;i++)
{
a=(a+k)%i;
b=(b+k)%i;
c=(c+k)%i;
}
a++,b++,c++;
printf("%d %d %d\n",a,b,c);
//printf("%d %d %d\n",fun(n,k,n-2)+1,fun(n,k,n-1)+1,fun(n,k,n)+1);
}
return ;
}
UVA 1452 八 Jump的更多相关文章
- Joseph UVA 1452 Jump
题目传送门 /* 数学:约瑟夫环问题的变形,首先定义f[i]表示剩下i个人时,最后一个选出的人,有个公式:f[i] = (f[i-1] + m) % i f[1] = 0(编号从0开始),那么类似最后 ...
- UVa 1452 递推 Jump
约瑟夫变形,先计算出3个数时,最后三个数字的编号. 然后以这三个数为起点,就可以递推出n个数对应的最后三个数字的编号. 递推公式都是一样的. #include <iostream> #in ...
- UVa 167(八皇后)、POJ2258 The Settlers of Catan——记两个简单回溯搜索
UVa 167 题意:八行八列的棋盘每行每列都要有一个皇后,每个对角线上最多放一个皇后,让你放八个,使摆放位置上的数字加起来最大. 参考:https://blog.csdn.net/xiaoxiede ...
- UVA 10254 十八 The Priest Mathematician
The Priest Mathematician Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu ...
- uva 167 - The Sultan's Successors(典型的八皇后问题)
这道题是典型的八皇后问题,刘汝佳书上有具体的解说. 代码的实现例如以下: #include <stdio.h> #include <string.h> #include < ...
- 【UVa】Jump(dp)
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- [ An Ac a Day ^_^ ] [kuangbin带你飞]专题八 生成树 UVA 10600 ACM Contest and Blackout 最小生成树+次小生成树
题意就是求最小生成树和次小生成树 #include<cstdio> #include<iostream> #include<algorithm> #include& ...
- 最小瓶颈路 Uva 534 Frogger
说明:关于Uva的题目,可以在vjudge上做的,不用到Uva(那个极其慢的)网站去做. 最小瓶颈路:找u到v的一条路径满足最大边权值尽量小 先求最小生成树,然后u到v的路径在树上是唯一的,答案就是这 ...
- UVA 572 Oil Deposits油田(DFS求连通块)
UVA 572 DFS(floodfill) 用DFS求连通块 Time Limit:1000MS Memory Limit:65536KB 64bit IO Format: ...
随机推荐
- 二项分布 多项分布 伽马函数 Beta分布
http://blog.csdn.net/shuimu12345678/article/details/30773929 0-1分布: 在一次试验中,要么为0要么为1的分布,叫0-1分布. 二项分布: ...
- 超链接点击后不显示hover
超链接访问过后 hover 样式就不出现了,被点击访问过的超链接样式不在具有 hover 和 active 了 解决方法:改变CSS属性的排列顺序 L-V-H-A a:link {} a:visite ...
- angularjs 相关资料
1.angularjs 框架结构 bootstrap process :http://www.oschina.net/translate/angularjs-the-next-big-thing?pr ...
- EL表达式简介
EL表达式简介 EL 全名为Expression Language.EL主要作用: 1.获取数据 EL表达式主要用于替换JSP页面中的脚本表达式,以从各种类型的web域 中检索java对象.获取数据. ...
- 161027、Java 中的 12 大要素及其他因素
对于许多人来说,"原生云"和"应用程序的12要素"是同义词.本文的目的是说有很多的原生云只坚持了最初的12个因素.在大多数情况下,Java 能胜任这一任务.在本 ...
- zabbix自定义监控tcp连接数
首先在客户端修改配置文件 # vim /usr/local/zabbix/etc/zabbix_agentd.conf UnsafeUserParameters=1 UserParameter=tcp ...
- php两种include加载文件方式效率比较如下
1)定义一个字符串变量,里面保存要加载的文件列表.然后foreach加载. $a = '/a.class.php;/Util/b.class.php;/Util/c.class.php'; $b = ...
- ASP.NET MVC3 Dynamically added form fields model binding
Adding new Item to a list of items, inline is a very nice feature you can provide to your user. Thi ...
- sqlite加密
一直使用sqlite来管理本地的数据,但是Xcode中的SDK中集成的sqlite是免费的,不提供加密模块,但是程序中用到的很多数据,有时候是不想让别人看到,一开始虑修改sqlite的源码,自己重新编 ...
- ecshop后台增加模板页的方法
CShop的动态模板机制是一个非常灵活的系统,管理员可以在后台根据自己的要求调整模板模块的显示位置.本文详细讲解了如何修改ECSHOP内部结构使得用户可以添加自己的模板页从而方便灵活的使用系统自带的模 ...