Routine Problem
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 abcd (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 pand q don't have a common divisor larger than 1.

将屏幕的宽度和影片画面的宽度设为一样,屏幕和影片的高根据比例做相应调整。若调整后屏幕的高>影片的高,则确定将影片的宽调整为屏幕的宽是正确的。否则表明应将影片的高调整为屏幕的高。

AC Code:

 #include <iostream>
#include <algorithm>
#include <cstdio> using namespace std; long long lcd(long long y, long long x)
{
long long r = x % y;
while(r){
x = y;
y = r;
r = x % y;
}
return y;
} int main()
{
long long a, b, c, d, p, q, m;
while(scanf("%I64d %I64d %I64d %I64d", &a, &b, &c, &d) != EOF){
if(a * d == b * c) {
puts("0/1");
continue;
}
b *= c;
d *= a;
a = c = a * c;
if(b > d){ //以宽为基准
p = b - d;
q = b;
}
else{ //以高为基准
p = d * a - b * c;
q = a * d;
}
m = lcd(p, q);
printf("%I64d/%I64d\n", p / m, q / m);
}
return ;
}

Routine Problem(数学)的更多相关文章

  1. codeforces B. Routine Problem 解题报告

    题目链接:http://codeforces.com/problemset/problem/337/B 看到这个题目,觉得特别有意思,因为有熟悉的图片(看过的一部电影).接着让我很意外的是,在纸上比划 ...

  2. UVa10025 The ? 1 ? 2 ? ... ? n = k problem 数学思维+规律

    UVa10025 ? 1 ? 2 ? ... ? n = k problem The problem Given the following formula, one can set operator ...

  3. POJ 3100 &amp; ZOJ 2818 &amp; HDU 2740 Root of the Problem(数学)

    题目链接: POJ:id=3100" style="font-size:18px">http://poj.org/problem? id=3100 ZOJ:http ...

  4. UVALive 6909 Kevin's Problem 数学排列组合

    Kevin's Problem 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid ...

  5. hdu 5105 Math Problem(数学)

    pid=5105" target="_blank" style="">题目链接:hdu 5105 Math Problem 题目大意:给定a.b ...

  6. hdu-5858 Hard problem(数学)

    题目链接: Hard problem Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Othe ...

  7. Codeforces Round #603 (Div. 2) A. Sweet Problem(数学)

    链接: https://codeforces.com/contest/1263/problem/A 题意: You have three piles of candies: red, green an ...

  8. Codeforces Round #196 (Div. 2) B. Routine Problem

    screen 尺寸为a:b video 尺寸为 c:d 如果a == c 则 面积比为 cd/ab=ad/cb (ad < cb) 如果b == d 则 面积比为 cd/ab=cb/ad  (c ...

  9. HDU 5105 Math Problem --数学,求导

    官方题解: f(x)=|a∗x3+b∗x2+c∗x+d|, 求最大值.令g(x)=a∗x3+b∗x2+c∗x+d,f(x)的最大值即为g(x)的正最大值,或者是负最小值.a!=0时, g′(x)=3∗ ...

随机推荐

  1. js从一个函数中结束另一个函数的问题

    等待通过事件监听结束另一函数的方法出炉…… 1.事件监听? 2.从a里把b函数全局定义一下,不推荐. function a(){ alert("a"); b=function(){ ...

  2. duilib进阶教程 -- 改进List控件 (16)

    一.控件隐藏后,允许用代码操作所有行为. 在做播放器的时候,最常用的功能莫过于顺序播放.随机播放了,而当我们切换歌曲的时候,显然应该选中该歌曲,List的选中函数是SelectItem,但是调用此函数 ...

  3. js程序设计02——变量、作用域问题

    首先,ECMAScript中的数据类型分为基本类型.引用类型,基本类型的访问操作是按值的.引用类型的值是保存在内存中的对象,操作对象时,实际上操作的是对象的引用,而非对象自身.“javascript高 ...

  4. iOS开发-友盟分享(3)

    iOS 友盟分享 这个主要是提到如何通过友盟去自定义分享的步骤: 一.肯定要去友盟官网下载最新的SDK包,然后将SDK导入到你的工程文件夹里面去: 二.注册友盟账号,将你的APP添加到你的账号里面然后 ...

  5. 使用tornado的gen模块改善程序性能

    之前在公司的一个模块,需要从另一处url取得数据,我使用了Python的一个很著名的lib,叫做requests.但是这样做极大的降低了程序的性能,因为tornado是单线程的,它使用了所谓的reac ...

  6. Leetcode 130 Surrounded Regions DFS

    将内部的O点变成X input X X X XX O O X X X O XX O X X output X X X XX X X XX X X XX O X X DFS的基本框架是 void dfs ...

  7. MySQL安全性语言

    文章为作者原创,未经许可,禁止转载.    -Sun Yat-sen University 冯兴伟 实验2:安全性语言 安全性实验包含两个实验项目,其中1个为必修,1个为选修.自主存取控制实验为设计型 ...

  8. win7给C盘扩容

    win7给C盘扩容 需要给C盘在不重装系统的情况下进行扩容.在网上搜索了不少资料,包括使用系统自带的分区工具,PQ等软件,都没有成功.不小心看到了分区助手,使用之,迅速的解决了问题,而且解决的非常完美 ...

  9. eclipse,myeclipse开发环境下,maven远程部署到tomcat7服务器(图文)

    有的人想在eclipse写java web 项目,通过maven也是一种实现的方法,可以实现java web 项目打包成war,发布到tomcat. 在pom.xml文件的build增加下面的代码,相 ...

  10. 恶心的sbt 超级慢--解决

    最近在看sbt相关的资料.发现其构建仓库是用ivy和maven 相信使用过maven的人都知道下载 jar的过程十分痛苦(因为你穷,买不起VPN) 然后我们天朝本来有开源中国的maven库,后来又突然 ...