0%

北大 acm 2707 Copier Reduction 解题报告

Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5969 Accepted: 3039

Description

What do you do if you need to copy a 560x400mm image onto a standard sheet of US letter-size paper (which is about 216x280mm), while keeping the image as large as possible? You can rotate the image 90 degrees (so that it is in “landscape” mode), then reduce it to 50% of its original size so that it is 200x280mm. Then it will fit on the paper without overlapping any edges. Your job is to solve this problem in general.

Input

The input consists of one or more test cases, each of which is a single line containing four positive integers A, B, C, and D, separated by a space, representing an AxBmm image and a CxDmm piece of paper. All inputs will be less than one thousand. Following the test cases is a line containing four zeros that signals the end of the input.

Output

For each test case, if the image fits on the sheet of paper without changing its size (but rotating it if necessary), then the output is 100%. If the image must be reduced in order to fit, the output is the largest integer percentage of its original size that will fit (rotating it if necessary). Output the percentage exactly as shown in the examples below. You can assume that no image will need to be reduced to less than 1% of its original size, so the answer will always be an integer percentage between 1% and 100%, inclusive.

Sample Input

560 400 218 28010 25 88 108 13 5 19 13 10 6199 333 40 275 90 218 280999 99 1 100 0 0 0

Sample Output

50%100%12%66%1%100%1%

题意:原图像大小为AxB压缩后为CxD,问压缩后为原来的百分比解法:对A,B,C,D排序实现A>B,C>D,然后在C/A,和D/B中取较小者

代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>

using namespace std;

int main()
{
float a,b,c,d,t,rotate;
float f;

while(cin>>a>>b>>c>>d)
{
if(a==0&&b==0&&c==0&&d==0)
break;

rotate=0;

if(a<b)
{
t=a;
a=b;
b=t;
}

if(c<d)
{
t=c;
c=d;
d=t;
}

f=c/a;

if(d/b<f)
f=d/b;

f=f*100;

if((int)f<100)
printf("%d%%\n",(int)f);
else
printf("100%%\n");
}
return 0;
}
谢谢您的打赏,我的大英雄 ^_^
Thank you for your generosity, my big hero ^_^

更多内容请关注公众号「西小玛」