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

OpenSoucre發表於2014-06-12

screen 尺寸為a:b

video 尺寸為 c:d

如果a == c 則 面積比為 cd/ab=ad/cb (ad < cb)

如果b == d 則 面積比為 cd/ab=cb/ad  (cb < ad)

如果不相等時

如果a/b > c/d,則ad/bd > cb/db 則(ad > cb)

  screen尺寸可為 ad:bd, video的尺寸可為 cb:db

  面積比為:cb*db/ad*bd = cb/ad (ad > cb)

如果a/b < c/d,則ac/bc < ca/da 則(ad < cb)

  screen尺寸可為 ac:bc, video的尺寸可為 ca:da

  面積比為:ca*da/ac*bc = ad/cb (ad < cb)

 綜合得面積比為min(ad,cb)/max(ad,cb)

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int gcd(int n, int m){
	while(m){
		int t = n%m;
		n = m;
		m = t;
	}
	return n;
}

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

  

相關文章