首页 > 代码库 > Codeforces Round #196 (Div. 2) B. Routine Problem

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  (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)

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#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;
}