Routine Problem(数学)
1 second
256 megabytes
standard input
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.
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 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(数学)的更多相关文章
- codeforces B. Routine Problem 解题报告
题目链接:http://codeforces.com/problemset/problem/337/B 看到这个题目,觉得特别有意思,因为有熟悉的图片(看过的一部电影).接着让我很意外的是,在纸上比划 ...
- UVa10025 The ? 1 ? 2 ? ... ? n = k problem 数学思维+规律
UVa10025 ? 1 ? 2 ? ... ? n = k problem The problem Given the following formula, one can set operator ...
- POJ 3100 & ZOJ 2818 & HDU 2740 Root of the Problem(数学)
题目链接: POJ:id=3100" style="font-size:18px">http://poj.org/problem? id=3100 ZOJ:http ...
- UVALive 6909 Kevin's Problem 数学排列组合
Kevin's Problem 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid ...
- hdu 5105 Math Problem(数学)
pid=5105" target="_blank" style="">题目链接:hdu 5105 Math Problem 题目大意:给定a.b ...
- hdu-5858 Hard problem(数学)
题目链接: Hard problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- Codeforces Round #603 (Div. 2) A. Sweet Problem(数学)
链接: https://codeforces.com/contest/1263/problem/A 题意: You have three piles of candies: red, green an ...
- 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 ...
- 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∗ ...
随机推荐
- 自己动手写js分享插件(QQ空间,微信,新浪微博。。。)
参考博客:http://blog.csdn.net/libin_1/article/details/52424340 下载链接:http://download.csdn.net/detail/come ...
- delegate 集成在类中,还是单独写在.h文件中?
转:http://stackoverflow.com/questions/11382057/declaring-a-delegate-protocol There definitely are sub ...
- Android CountDownTimer倒计时器的使用
http://blog.csdn.net/freesonhp/article/details/25904047 在平时我们编程的时候,经常会用到倒计时这个功能,很多人不知道Android已经帮封装好了 ...
- Revit如何设置尺寸标注的箭头样式
在尺寸标注类型属性中,有一名称为"记号标记"的属性,该属性控制线性标注的箭头样式,如图所示,可以从下"记号标记"下拉列表中选择需要的样式进行设置,但是有时候该下 ...
- GTD时间管理---非行动性
一:行动性和非行动有什么区别? 1:非行动性:指的是收集箱中的信息,是先存储后使用,这些信息平时都处于冬眠状态,只是要用到的时候能够找到它就好了.(偏向于处理生活) 2:行动性: 指的是收集箱中的信息 ...
- Maven full settings.xml
<?xml version="1.0" encoding="UTF-8"?> <!-- Licensed to the Apache Soft ...
- 奇怪吸引子---TreeScrollUnifiedChaoticSystem
奇怪吸引子是混沌学的重要组成理论,用于演化过程的终极状态,具有如下特征:终极性.稳定性.吸引性.吸引子是一个数学概念,描写运动的收敛类型.它是指这样的一个集合,当时间趋于无穷大时,在任何一个有界集上出 ...
- 用C#表达式树优雅的计算24点
思路:一共4个数字,共需要3个运算符,可以构造一个二叉树,没有子节点的节点的为值,有叶子节点的为运算符 例如数字{1, 2, 3, 4},其中一种解的二叉树形式如下所示: 因此可以遍历所有二叉树可能的 ...
- Scala 深入浅出实战经典 第54讲:Scala中复合类型实战详解
王家林亲授<DT大数据梦工厂>大数据实战视频 Scala 深入浅出实战经典(1-64讲)完整视频.PPT.代码下载:百度云盘:http://pan.baidu.com/s/1c0noOt6 ...
- 杀死O2O的三大杀手?!
0个O2O领域,20多个“已故”项目,三种不同的死因……记者糜丰.孙锋将O2O项目的一些固有问题分析得淋漓尽致! 这三个O2O杀手分别是:买不起的流量.承担不起的物流成本.惹不起的传统企业. 除了找钱 ...