首页 > 其他 > 详细

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

时间:2014-06-13 17:12:11      阅读:419      评论:0      收藏:0      [点我收藏+]

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

  

Codeforces Round #196 (Div. 2) B. Routine Problem,布布扣,bubuko.com

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

原文:http://www.cnblogs.com/xiongqiangcs/p/3784616.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!