Codeforces Round #196 (Div. 2) B. Routine Problem
来源:互联网 发布:网络模式nat 编辑:程序博客网 时间:2024/05/21 19:47
题目大意:给你显示器屏幕的比例(a:b)和你要看电影的比例(c:d),求调整后剩下的没有到的区域和总面积的比例。
题目分析:在做虚拟赛的时候,对自己的想法不是很确定,能否AC。在提交WA后,就果断放弃了。第二天在做的时候发现是自己特例没想到。虽说我的想法很笨拙,但是还是能AC的。反正就是定长比宽,或者是定宽比长。
下面是代码:
#include <iostream>#include <stdio.h>using namespace std;int gcd(int a,int b){ return b == 0 ? a : gcd(b,a%b);}int main(){ int a,b,c,d; cin>>a>>b>>c>>d; int g1 ,g2; g1 = gcd(a,b); g2 = gcd(c,d); if(g1 != 1) a /= g1,b /= g1; if(g2 != 1) c /= g2,d /= g2; if(a == b) a = 1,b = 1; if(c == d) c = 1,d = 1; double t1 = (double)a/b; double t2 = (double)c/d; //printf("%lf\n",t1); // printf("%lf\n",t2); int com; if(t1 < t2) { g1 = gcd(a,c); com = (a * c)/g1/a; b = b*com; com = (a*c)/g1/c; d = d*com; g1 = gcd(b,d); b /= g1; d /= g1; printf("%d/%d\n",(b-d),b); } else if(t1 > t2) { g2 = gcd(b,d); com = (b*d)/g2/b; a = a * com; com = (b*d)/g2/d; c = c * com; g2 = gcd(a,c); a /= g2; c /= g2; printf("%d/%d\n",(a-c),a); } else printf("0/1\n"); return 0;}
PS:代码写的很戳....
- Codeforces Round #196 (Div. 2) B. Routine Problem
- Codeforces Round #196 (Div. 2) / 337B Routine Problem(数学)
- Codeforces Round #196 (Div. 2) B. Routine Problem
- CodeForces#196Div.2-B. Routine Problem
- Codeforces Round #170 (Div. 2) problem B
- Codeforces Round #173 (Div. 2) Problem B
- Codeforces Round #311 (Div. 2) Problem B
- Codeforces Round #363 (Div. 2), problem: (B)
- Problem E Codeforces Round #184 (Div. 2) B. Continued Fractions
- Problem G B. Calendar Codeforces Round #183 (Div. 2)
- Codeforces Round #FF (Div. 2) Problem B DZY Loves Strings
- Codeforces Round #170 (Div. 2) B. New Problem
- Codeforces Round #279 (Div. 2), problem: (B) Queue
- Codeforces Round #343 (Div. 2) B. Far Relative’s Problem
- Codeforces Round #343 (Div. 2) Problem A & B
- Codeforces Round #343 (Div. 2) B. Far Relative’s Problem
- Codeforces Round #437 (Div. 2) B. Save the problem!
- Codeforces Round #367 (Div. 2)E. Working routine
- 强连通分量-Tarjin算法
- STL String 非常详细 的介绍
- ACCESS 数据库之窗体的用途及设计
- [.Net码农]BulkCopytoSQL做批量导入
- Objective-C 编程语言(7)关联
- Codeforces Round #196 (Div. 2) B. Routine Problem
- 字典树Trie算法
- 如何解决网页中的中文乱码现象
- (android 功能代码) android app集成支付宝
- POJ 1392 - Ouroboros Snake 求0011这类序列欧拉回路的最小路径...
- javascript控制图片旋转
- 第五章 Spring3.0 、Hibernate3.3与Struts2的整合 基于Annotation
- 把excel表中的数据导入到SQL Server2008的库中
- Oracle中的MINUS和UNION用法(转)