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

时间:2022-07-11 16:12:29

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;
}