Codeforces Round #196 (Div. 2) B. Routine Problem
来源:互联网 发布:讲文明知礼仪的故事 编辑:程序博客网 时间:2024/05/22 08:16
Manao has a monitor. The screen of the monitor has horizontal to vertical length ratio a:b. Now he is going to watch a movie. The movie's frame has horizontal to vertical length ratio c:d. Manao adjusts the view in such a way that the movie preserves the original frame ratio, but also occupies as much space on the screen as possible and fits within it completely. Thus, he may have to zoom the movie in or out, but Manao will always change the frame proportionally in both dimensions.
Calculate the ratio of empty screen (the part of the screen not occupied by the movie) to the total screen size. Print the answer as an irreducible fraction p / q.
A single line contains four space-separated integers a, b, c, d (1 ≤ a, b, c, d ≤ 1000).
Print the answer to the problem as "p/q", where p is a non-negative integer, q is a positive integer and numbers p and q don't have a common divisor larger than 1.
1 1 3 2
1/3
4 3 2 2
1/4
Sample 1. Manao's monitor has a square screen. The movie has 3:2 horizontal to vertical length ratio. Obviously, the movie occupies most of the screen if the width of the picture coincides with the width of the screen. In this case, only 2/3 of the monitor will project the movie in the horizontal dimension:
Sample 2. This time the monitor's width is 4/3 times larger than its height and the movie's frame is square. In this case, the picture must take up the whole monitor in the vertical dimension and only 3/4 in the horizontal dimension:
#include <iostream>#include <stdio.h>#include <string.h>using namespace std;int gcd(int a,int b){ if(a==0) return b; return gcd(b%a,a);}int main(){ int a1,a2,a3,a4,l1,l2,l3; //printf("%d",gcd(2,4)); while(scanf("%d%d%d%d",&a1,&a2,&a3,&a4)!=EOF) { l1=a1*a4,l2=a2*a3; if(l1>l2) { l2=l1-l2; l3=gcd(l1,l2); l1/=l3,l2/=l3; printf("%d/%d\n",l2,l1); } else if(l1==l2) { printf("0/1\n"); } else if(l1<l2) { l1=l2-l1; l3=gcd(l1,l2); l1/=l3,l2/=l3; printf("%d/%d\n",l1,l2); } } return 0;}
- 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
- UVALive 3027 Corporative Network
- RobotFramework+Selenium2环境搭建与入门实例
- eclipse hadoop开发环境配置
- Codeforces Round #196 (Div. 2) A. Puzzles
- 【黑马程序员】java I/O流浅谈
- Codeforces Round #196 (Div. 2) B. Routine Problem
- UVA 11988 Broken Keyboard (a.k.a. Beiju Text)
- QT中新建的类继承QWidget和QMainWindow的不同之处
- 如何基于卫星地图制作矢量化电子地图
- hdu 4324
- 简单文件操作(Linux下C++实现) 打开,读取 写入 关闭
- 找回EC2的Key Pair文件
- Android SDK/Android.bat does not find SWT.jar file
- 05-session的增删改查