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∗ ...
随机推荐
- Qt之Dialog\widget\ mainwindow的区别和布局管理器 & 分裂器的区别
1.Dialog\widget\ mainwindow的区别 注意mainwindow和widget的区别,mainwindow都工具栏和菜单栏 Dialog and mainwinodws 都是继承 ...
- crossplatform---bower解决js的依赖管理
从零开始nodejs系列文章,将介绍如何利Javascript做为服务端脚本,通过Nodejs框架web开发.Nodejs框架是基于V8的引擎,是目前速度最快的Javascript引擎.chrome浏 ...
- celery与mangodb搭配应用
写作背景介绍 在celery简单应用中已经介绍了如何去配置一个celery应用,也知道怎么分离任务逻辑代码与客户端代码了.我们现在的任务是怎么把计算结果保存到数据库中,这种数据持久化是非常重要的.你一 ...
- Extjs4中RadioGroup的赋值与取值
1.定义rg var rg = new Ext.form.RadioGroup({ fieldLabel : "test", items : [{ boxLabel : '每天', ...
- Leetcode-203 Remove Linked List Elements
#203. Remove Linked List Elements Remove all elements from a linked list of integers that have val ...
- android: 多线程编程基础
9.1 服务是什么 服务(Service)是 Android 中实现程序后台运行的解决方案,它非常适合用于去执行那 些不需要和用户交互而且还要求长期运行的任务.服务的运行不依赖于任何用户界面,即使 ...
- go语言实现一个简单的登录注册web小程序
最近学习golang也有一段时间了,基础差不多学了个大概,因为本人是java程序员,所以对web更感兴趣.根据<go web编程>中的例子改编一个更简单的例子,供新手参考,废话不多说,上菜 ...
- Socket原理与编程基础(转)
一.Socket简介 Socket是进程通讯的一种方式,即调用这个网络库的一些API函数实现分布在不同主机的相关进程之间的数据交换. 几个定义: (1)IP地址:即依照TCP/IP协议分配给本地主机的 ...
- Mysql自动备份工具1.0(2013年11月15日更新)
Mysql自动备份工具1.0 下载地址 2013-11-15 1.解决日历控件在Windows7/8/8.1环境下遮挡按钮问题:2.解决按月备份当月没有该日期问题: 2013-11-13 1.Mysq ...
- Requirements of an SAP system administrator
Requirements of an SAP system administrator Have a "proper" attitude Protect and safeguard ...