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)

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

  

上一篇:在linux oracle 10g/11g x64bit环境中,goldengate随os启动而自己主动启动的脚本


下一篇:Oracle 10g安全加固(审计、监听密码)