hdu 1722 Cake 数学yy】的更多相关文章

题链:http://acm.hdu.edu.cn/showproblem.php? pid=1722 Cake Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2620    Accepted Submission(s): 1364 Problem Description 一次生日Party可能有p人或者q人參加,现准备有一个大蛋糕.问…
题意:就是一个蛋糕,被分成n或者m份.问最少动几刀. 看一下这个图,就知道公式了,n+m-gcd(n, m); #include<cstdio> #include<iostream> using namespace std; #define ll long long ll gcd(ll a, ll b){ ? a : gcd(b, a%b); } int main() { ll n, m; while (scanf("%lld%lld", &n, &am…
Big Number 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1722 ——每天在线,欢迎留言谈论. 题目大意: 给你两个数 n1,n2 . 然后你有一块蛋糕,提前切好,使得不管来 n1 还是 n2 个人都能够当场平均分配. 求 “提前切好” 的最小蛋糕块数. 知识点: (请无视)公式:N = a + b + gcd(a, b) : 思路: (勿无视)先份成p块,然后再拼到一起,再从原来开始的地方,将蛋糕再分成q份,中间肯定会出现完全重合的块…
#include<cstdio> int gcd(int m, int n) { ?n:gcd(n % m, m); } int main() { int m, n; while(scanf("%d%d",&m,&n)!=EOF) { printf("%d\n", m + n - gcd(m, n)); } ; } 题解:考虑切蛋糕为q块需要q刀,p块需要p刀,但是两者切痕有重叠,重叠部分为两者的最大公约数,所以问题就迎刃而解了.…
#include<iostream> #include<stdio.h> #include<math.h> using namespace std; long long gcd(long long a,long long b) { ?a:gcd(b,a%b); } int main() { long long a,b; while(cin>>a>>b)//这道题居然是多CASE= =,题目也不给说一声 cout<<a+b-gcd(a,…
HDU 5355 Cake 更新后的代码: 今天又一次做这道题的时候想了非常多种思路 最后最终想出了自觉得完美的思路,结果却超时 真的是感觉自己没救了 最后加了记忆化搜索,AC了 好了先说下思路吧.不知道大家住没注意m<=10 我们能够把大部分的数据写成成对的形式比如n=27 m=6的这组数据 第1份  27  16 第2份  26  17 第3份  25  18 第4份  24  19 第5份  23  20 第6份  22  21 剩下1~15搜索出6等份分给全部人 这样成对出现的数蛇形数我…
Robot 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5673 Description There is a robot on the origin point of an axis.Every second, the robot can move right one unit length or do nothing.If the robot is on the right of origin point,it can also move…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5355 题意:给你n个尺寸大小分别为1,2,3,…,n的蛋糕,要求你分成m份,要求每份中所有蛋糕的大小之和均相同,如果有解,输出“YES”,并给出每份的蛋糕数及其尺寸大小,否则输出“NO” 例如n=5,m=3,即大小尺寸分别为1,2,3,4,5的5个蛋糕,要求分成三份,那么解可以是第一份一个蛋糕,大小为5:第二份两个蛋糕,大小为1.4:第三份两个蛋糕,大小为2.3.这样每份大小之和均为5,满足题目要求…
题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=5355 题面: Cake Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 1632    Accepted Submission(s): 273 Special Judge Problem Description There are m…
Triangle 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5914 Description Mr. Frog has n sticks, whose lengths are 1,2, 3⋯n respectively. Wallice is a bad man, so he does not want Mr. Frog to form a triangle with three of the sticks here. He decides…