Codeforces Round #196 (Div. 2)

本文探讨了在不同屏幕尺寸下调整电影画面比例,以充分利用屏幕空间并保持原始画面比例的技术。通过计算空屏面积与总屏幕面积的比例,提供了一种高效的方法来优化观影体验。
B. 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 ratioa:b. Now he is going to watch a movie. The movie's frame has horizontal to vertical length ratioc: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 fractionp / 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 numbersp 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:


总结:参考了位同学的,主要是可按边长或宽两种参考来处理,但能够先排除一种而不用去计算两种,不可行再排除

参考代码:

/*
    *  Author: pirate
	 *  Created on: 2013年8月17日
	  *  196DIV2B.cpp    
	   */
#include <set>
#include <map>
#include <list>
#include <deque>
#include <queue>
#include <cmath>
#include <bitset>
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <fstream>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
#define N 1000000
#define I64 __int64
#define LL long long
#define PI acos(-1.0)
#define L(a) ((a)<<1)
#define R(a) ((a)<<1+1)
#define sqr(a) ((a)*(a))
#define MID(a,b) ((a)+(b))/2
#define ABS(a) (a)>0?(a):(-a)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define INIT(a,b) memset(a,b,sizeof(a))
int gcd(int x, int y) {
	    if (y == 0)
			        return x;
		    else
				        return gcd(y, x % y);
}
int lcm(int x, int y) {
	    return x / gcd(x, y) * y;
}
int main() {
	    int a, b, c, d;
		    cin >> a >> b >> c >> d;
			    if (a * d < b * c) {
					        int tmp;
							        tmp = a, a = b, b = tmp;
									        tmp = c, c = d, d = tmp;
											    }
				    a *= lcm(b, d) / b;
					    c *= lcm(b, d) / d;
						    int g = gcd(a, c);
							    a /= g;
								    c /= g;
									    printf("%d/%d\n", (a - c) / gcd(a - c, a), a / gcd(a - c, a));
										    return 0;
}

参考后最终的代码

#include <iostream>

using namespace std;

#define swap(a, b) do{ (a) = (a) ^ (b); (b) = (a) ^ (b); (a) = (a) ^ (b); }while(0)
#define lcm(a,b)   (a)*(b)/(gcd(a,b))

inline int gcd(int a, int b)
{
	int tmp;
	while(b){
		tmp = a%b;
		a = b;
		b = tmp;
	}
	return a;
}

int a, b, c, d;
int main()
{	
	cin >> a >> b >> c >> d;
	if(a*d < b*c)
	{
		swap(a,b);
		swap(c,d);
	}
	a *=lcm(b, d)/b;
	c *=lcm(b, d)/d;
	cout << (a - c)/gcd(a, a-c) << "/" << a/gcd(a, a-c) << endl;
}






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值