hdu acm steps 2.1.3
2011-10-09 20:12
411 查看
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1713
也是最大公约数的应用。
转载:题目输入c1/t1 c2/t2 ,也就是速度的分数形式,转换成: c1*t2/(t1*t2) , c2*t1/( t1*t2 ) ;
只需要求出分子的最小公倍数k,然后k/( t1*t2 )就是题目求的周期。
注意要用__int64.
下面是AC代码:
也是最大公约数的应用。
转载:题目输入c1/t1 c2/t2 ,也就是速度的分数形式,转换成: c1*t2/(t1*t2) , c2*t1/( t1*t2 ) ;
只需要求出分子的最小公倍数k,然后k/( t1*t2 )就是题目求的周期。
注意要用__int64.
下面是AC代码:
#include<iostream> #include<cstdio> #include<algorithm> using namespace std; __int64 gcd(__int64 a,__int64 b) { return b>0?gcd(b,a%b):a; } __int64 min_times(__int64 x1,__int64 x2) { __int64 c=gcd(x1,x2); return x1*x2/c; } int main() { __int64 cas,c1,c2,t1; __int64 t2,p,k,m,n,h; scanf("%I64d",&cas); while(cas--) { scanf("%I64d/%I64d",&c1,&t1); scanf("%I64d/%I64dd",&c2,&t2); k=t1*t2; m=t2*c1; n=t1*c2; p=min_times(m,n); h=gcd(p,k); if(h==k) { printf("%I64d\n",p/h); } else { printf("%I64d/%I64d\n",p/h,k/h); } } return 0; }
相关文章推荐
- hdu acmsteps 2.1.3 cake
- hdu acmsteps 2.1.3 Cake
- hdu ACM steps 1.2.6 hdu3361
- HDU ACM Steps攻略 ACM Steps的全部内容
- HDU ACM Steps解题报告
- hdu acmsteps 2.2
- HDU ACMSteps 1.3.2:: 今年暑假不AC(动态规划)
- hdu ACM steps 1.2.7 hdu 2629
- hdu 1443 or ACM steps 2.2.2
- hdu acmsteps 2.1
- hdu acm steps 1.3.1
- hdu ACM Steps 1.3.5 排序
- ACM--steps--dyx--1.3.8--Fighting for HDU
- hdu-acm stepsHumble Numbers
- hdu acm steps 1.3.2
- [小结]HDU ACM Steps
- hdu-acm steps Common Subsequence
- hdu acm steps 1.3.3
- hdu acmsteps 2.1.1 最小公倍数(GCD)
- HDU OJ ACM Steps 上的题目详细介绍