Game of Peace
Time Limit: 4000ms, Special Time Limit:10000ms, Memory Limit:65536KB Total submit users: 20, Accepted users: 12 Problem 13553 : No special judgement
Problem description Bob has learned a new magic trick that needs a very special preparation. Once he masters the trick he will be able to bring peace to the world, but if he fails, the world will be destroyed.
The preparation is performed as follows: There are two containers, initially one is empty and the other one has X marbles. Bob has a Marble Cloning Machine, it clones the marbles in the container with the larger number of marbles, then pours the new clones into the other container (e.g. if the two containers have 7 and 4 marbles, after the cloning step they will have 7 and 11 marbles). The machine does this cloning operation exactly M times. However, there is a bug in the machine, after it performs N cloning operations (N ≤ M ), it will add Y extra marbles to the container with the larger number of marbles. Then the machine will continue normally with the cloning operation exactly M - N times.
During the cloning operations, if both containers have the same number of marbles, any of them can be considered the one with the larger number of marbles.
Now, the bug in Bob’s machine is threatening to destroy the world. But his nerdy friend Alice told him that she knows how to fix it. All he has to do is to calculate the greatest common divisor of the sizes of the two containers after the cloning machine is done. Can you help Bob save the world?
Input Your program will be tested on one or more test cases. The first line of the input will be a single integer T (1 ≤ T ≤ 1,000) representing the number of test cases. Followed by T test cases. Each test case will consist of a single line, containing 4 integers separated by a single space X , N , Y and M (1 ≤ X , Y ≤ 1,000) (0 ≤ N ≤ 70) (N ≤ M ≤ 100,000) which are the numbers as described above.
Output For each test case print a single line containing “Case n:” (without quotes) where n is the test case number (starting from 1) followed by a space then the greatest common divisor of the sizes of the two containers after the machine is done.
Sample Input 2
4 3 6 5
5 1 15 2Sample Output Case 1: 2
Case 2: 5Judge Tips Note In the first sample test case, the number of marbles in each container will be the following after each step: (4, 0), (4, 4), (4, 8), (12, 8), (18, 8), (18, 26), (44, 26). The greatest common divisor of 44 and 26 is 2.
题意:
有两个容器,一个为空,另一个有x大理石,总共有m次操作,每次操作可以从两容器较大的一个中克隆所有大理石并加到另一个容器中,执行完第n次操作后要在较大的容器中额外加入y大理石,再继续剩余m-n操作。求最终两容器中个数的最大公约数。
附AC代码:
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
using namespace std; typedef __int64 ll; ll t,x,n,y,m;
ll a,b; ll GDC(ll a,ll b){
return (b>)?GDC(b,a%b):a;
} int main(){
while(cin>>t&&t){
int ans=;
while(t--){
cin>>x>>n>>y>>m;
a=;
b=x;
for(int i=;i<=n;i++){
if(b>a){
a+=b;
}
else{
b+=a;
}
} if(a>=b){
a+=y;
}
else{
b+=y;
} ll sum;
if(a>b){
sum=GDC(a,b);
}
else{
sum=GDC(b,a);
}
printf("Case %d: %I64d\n",ans,sum);
ans++;
}
}
return ;
}
Game of Peace的更多相关文章
- MYSQL分页存储过程及事务处理--转自peace
MYSQL的分页过程,和事务处理的一个测试过程. /* --名称:MYSQL版查询分页存储过程 by peace 2013-8-14 --输入参数:@fields -- 要查询的字段用逗号隔开 --输 ...
- Find the peace with yourself
The purpose of being mature is to find the real calm and peace with yourself. Or you can say the tur ...
- The Real Meaning of Peace
The Real Meaning of Peace There once was a king who offered a prize to the artist who would paint th ...
- UX设计案例研究:建立更好的用户体验(重新设计Air Peace Airline网站)
以下内容由Mockplus团队翻译整理,仅供学习交流,Mockplus是更快更简单的原型设计工具. 坐飞机旅行总是能给人带来很棒的体验,但我认为应该考虑预订航班时给用户带来的压力.在如今的数字世界,我 ...
- HDU 5434 Peace small elephant 状压dp+矩阵快速幂
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5434 Peace small elephant Accepts: 38 Submissions: ...
- 2018.09.28 hdu5434 Peace small elephant(状压dp+矩阵快速幂)
传送门 看到n的范围的时候吓了一跳,然后发现可以矩阵快速幂优化. 我们用类似于状压dp的方法构造(1(1(1<<m)∗(1m)*(1m)∗(1<<m)m)m)大小的矩阵. 然后 ...
- Crystal Clear Applied: The Seven Properties of Running an Agile Project (转载)
作者Alistair Cockburn, Crystal Clear的7个成功要素,写得挺好. 敏捷方法的关注点,大家可以参考,太激动所以转载了. 原文:http://www.informit.com ...
- MongoDB学习笔记二—Shell操作
数据类型 MongoDB在保留JSON基本键/值对特性的基础上,添加了其他一些数据类型. null null用于表示空值或者不存在的字段:{“x”:null} 布尔型 布尔类型有两个值true和fal ...
- Peter Hessler和他的中国三部曲(上)
大约一年前,我从<英语铺子>栏目知道了Peter Hessler这位作家.主播分享了她的一些读后感和印象深刻的片段,当然主要是主播的声音太甜了,让我对这位美国作家留下了深刻的印象. Pet ...
随机推荐
- Android 中View仅仅能接收到ACTION_DOWN无法接收ACTION_MOVE和ACTION_UP解决的方法
昨天晚上调试了一晚上,在LinearLayout上接收屏幕动作,可是出现了问题, 以下的代码是本人调的代码 </pre><pre name="code" clas ...
- SQL查询刚開始学习的人指南读书笔记(三)值表达式
CHAPTER 5 Getting More Than Simple Columns Intro Value expression,it contains column names, literal ...
- crazyflie2.0 RCC时钟知识
因为眼下手里仅仅有16MHZ的2520封装的贴片晶振,8MHZ这样的封装做不到这么小,所以就先用16MHZ,这样我们就须要改动程序相关的RCC时钟: 1,stm32f4xx.h #define HSE ...
- php 面向对象的三大要素(封装、继承、多态)以及重写(override)和重载(overload)的举例说明
PHP是一种HTML内嵌式的,用来制作动态网页的服务器端的脚本语言.其特点是:开发周期短,稳定安全,简单易学,免费开源,良好的跨平台特性.PHP是一种面向对象的程序设计语言,目前已成为全球最受欢迎的五 ...
- 2018.11.23-day25 面向对象-封装
1.经典类 2.多态 3.鸭子类型 4.封装
- The server must be started under an unprivileged user ID to prevent
mysql8 PostgreSQL [root@test local]# postgres -D /usr/local/pgsql/data"root" execution of ...
- rac_udev建立磁盘方式安装grid时不识别磁盘
原创作品,出自 "深蓝的blog" 博客,欢迎转载,转载时请务必注明下面出处,否则追究版权法律责任. 深蓝的blog:http://blog.csdn.net/huangyanlo ...
- docker: docker安装和镜像下载
1 安装docker的apt源 apt-get install apt-transport-https ca-certificates curl software-properties-common ...
- ORACLE函数之单行转换函数
1 ASCIISTR 格式:ASCIISTR(C) 说明:将字符串C转换为ASCII字符串,即将C中的ASCII字符保留不变,但非ASCII字符则以ASCII表示返回 举例: ...
- mac shell命令连接mongo
1. 安装rebomongo 2. mongo 192.168.1.100/databasename -u lsg -p 123456 3.db.drawspecs.find({name:'prize ...