B. Routine Problem
2013-09-25 09:18
232 查看
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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.
Input
A single line contains four space-separated integers a, b, c, d (1 ≤ a, b, c, d ≤ 1000).
Output
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.
Sample test(s)
input
output
input
output
Note
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:
解题说明:题目要求在确保影片比例不变的情况下让影片尽可能大的占据屏幕,这也就意味着影片画面肯定有两边与屏幕的边重合,故只有两种情况,长等于长,宽等于宽,然后求出空白所占的比例即可。如果长等于长,即有c = a,d = a*d/c;所以电影面积与屏幕面积的比就是c*d/(a*b),代入得a*d/(b*c)。同理,如果是的宽相等d = b;c = c*b/d;最后得到c*b/(a*d)。
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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.
Input
A single line contains four space-separated integers a, b, c, d (1 ≤ a, b, c, d ≤ 1000).
Output
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.
Sample test(s)
input
1 1 3 2
output
1/3
input
4 3 2 2
output
1/4
Note
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:
解题说明:题目要求在确保影片比例不变的情况下让影片尽可能大的占据屏幕,这也就意味着影片画面肯定有两边与屏幕的边重合,故只有两种情况,长等于长,宽等于宽,然后求出空白所占的比例即可。如果长等于长,即有c = a,d = a*d/c;所以电影面积与屏幕面积的比就是c*d/(a*b),代入得a*d/(b*c)。同理,如果是的宽相等d = b;c = c*b/d;最后得到c*b/(a*d)。
#include <iostream> #include<algorithm> #include<cstdio> #include<cmath> #include<cstring> #include<cstdlib> using namespace std; int gcd(int a, int b) { if(b==0) { return a; } else { return gcd(b, a%b); } } int main() { int a,b,c,d; scanf("%d %d %d %d",&a,&b,&c,&d); a*=d; b*=c; if(a>b) { swap(a,b); } a=b-a; c=gcd(a,b); printf("%d/%d\n",a/c,b/c); return 0; }
相关文章推荐
- 107条Javascript的常用语句
- iPhone4升级iOS7输入卡顿的完美解决办法
- 谷歌Quickoffice现免费面向所有用户
- C++中拷贝构造函数的总结详解
- css3 中background的新增加的属性的用法(一)
- windows7系统自动扫描安装驱动的功能如何关闭
- MapReduce Design Patterns-chapter 6
- python脚本替换指定行
- 新iPad猜想:64位9.7寸产品 风头胜Mini
- 多线程的自然分裂管理法
- 如何启动eclipse时提示选择工作空间 || 删除workspace空间的目录
- 修改Dreamweaver支持自定义的后缀文件,使用设计视图,支持颜色提示
- 谷歌Quickoffice现免费面向所有用户
- JavaScript And Ajax(呈现脚本块、脚本注入攻击)
- maven 常用的在线仓库,可以省去很多手动配置的麻烦
- String类型的NULL与空串
- 异构平台
- Qt绘制贝塞尔曲线
- 八位知名设计师评iOS7:新鲜但复杂
- 關於復興中國文化的系列思考