hdu 5640 King's Cake(BestCoder Round #75)
King's Cake
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 736 Accepted Submission(s): 539
For each testcase, the first line and the only line contains two positive numbers n,m(1≤n,m≤10000).
For the first testcase you can divide the into one cake of $2\times2$ , 2 cakes of $1\times 1$
#include<stdio.h>
#include<string.h>
#include<cstdio>
#include<string>
#include<math.h>
#include<algorithm>
#define LL long long
#define PI atan(1.0)*4
#define DD double
#define MAX 3000010
#define mod 100
#define dian 1.000000011
#define INF 0x3f3f3f
using namespace std;
int main()
{
LL n,m,j,i,k,sum,Max,Min;
int t;
scanf("%d",&t);
while(t--)
{
//printf("1\n");
scanf("%lld%lld",&n,&m);
if(n==m)
{
printf("1\n");
continue;
}
int x;
sum=0;k=0;
Min=min(n,m);
Max=max(n,m);
while(Max!=1&&Min!=1)
{
Max-=Min;
k++;
if(Max<Min)
{
x=Max;
Max=Min;
Min=x;
}
if(Max==Min)
break;
}
if(Max==Min)
printf("%lld\n",k+1);
else if(Max!=Min&&Min==1)
{
sum=sum+k+Max;
printf("%lld\n",sum);
}
}
return 0;
}
hdu 5640 King's Cake(BestCoder Round #75)的更多相关文章
- hdu 5640 King's Cake(模拟)
Problem Description It is the king's birthday before the military parade . The ministers prepared ...
- HDU 5806 - NanoApe Loves Sequence Ⅱ (BestCoder Round #86)
若 [i, j] 满足, 则 [i, j+1], [i, j+2]...[i,n]均满足 故设当前区间里个数为size, 对于每个 i ,找到刚满足 size == k 的 [i, j], ans + ...
- HDU 5805 - NanoApe Loves Sequence (BestCoder Round #86)
先找相邻差值的最大,第二大,第三大 删去端点会减少一个值, 删去其余点会减少两个值,新增一个值,所以新增和现存的最大的值比较一下取最大即可 #include <iostream> #inc ...
- hdu 5641 King's Phone(暴力模拟题)
Problem Description In a military parade, the King sees lots of new things, including an Andriod Pho ...
- HDU 5640 King's Cake GCD
King's Cake 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5640 Description It is the king's birthd ...
- HDU 5640 King's Cake
King's Cake Problem Description It is the king's birthday before the military parade . The ministers ...
- hdu 5063 Operation the Sequence(Bestcoder Round #13)
Operation the Sequence Time Limi ...
- HDU 5640 King's Cake【模拟】
题意: 给定长方形,每次从中切去一个最大的正方形,问最终可以得到多少正方形. 分析: 过程类似求gcd,每次减去最小的边即可. 代码: #include <cstdio> #include ...
- BestCoder Round #75 1001 - King's Cake
Problem Description It is the king's birthday before the military parade . The ministers prepared a ...
随机推荐
- 函数buf_page_hash_get_low
/******************************************************************//** Returns the control block of ...
- 基于XMPP的即时通信系统的建立(二)— XMPP详解
XMPP详解 XMPP(eXtensible Messaging and Presence Protocol,可扩展消息处理和现场协议)是一种在两个地点间传递小型结构化数据的协议.在此基础上,XMPP ...
- CodeForces 489A (瞎搞) SwapSort
题意: 给n个整数(可能有重复),输出一个不超过n次交换的方案,使得经过这n次交换后,整个序列正好是非递减的. 分析: 首先说题解给的算法. 从左到右扫一遍,交换第i个数和它后面最小的那个数. 代码看 ...
- UVa 10129 Play On Words【欧拉道路 并查集 】
题意:给出n个单词,问这n个单词能否首尾接龙,即能否构成欧拉道路 按照紫书上的思路:用并查集来做,取每一个单词的第一个字母,和最后一个字母进行并查集的操作 但这道题目是欧拉道路(下面摘自http:// ...
- ASP.NET在IE10,IE11中Form表单身份验证失效问题解决方法
已经研究出解决方案. 在web.config中的forms中增加cookieless="UseCookies"属性即可. <authentication mode=&qu ...
- Relativelayout属性
// 相对于给定ID控件 android:layout_above 将该控件的底部置于给定ID的控件之上; android:layout_below 将该控件的底部置于给定ID的控件之下; andro ...
- [转]Jquery Ajax用法
原文地址:http://www.php100.com/html/program/jquery/2013/0905/6004.html jQuery学习之jQuery Ajax用法详解 来源: 时间 ...
- Deferred的那些知识
在移动开发中的各种中,我们一定会遇到异步回调的问题,比如: 1:Css3执行动画完毕, 回调 2:Jquery Animate动画的执行完毕, 回调 3:Ajax的执行(并行.串行),回调 等等 ...
- hdu 2204 Eddy's爱好
// 一个整数N,1<=N<=1000000000000000000(10^18).// 输出在在1到N之间形式如M^K的数的总数// 容斥原理// 枚举k=集合{2,3,5,7,11,1 ...
- Android UncaughtExceptionHandler,捕获错误
最近在做个项目,需要在程序出现运行时异常和错误导致程序crash时进行一些操作,找到一个方法 Thread.setDefaultUncaughtExceptionHandler(new Uncaugh ...