TOJ 1887.Copier Reduction

题目链接:http://acm.tju.edu.cn/toj/showp1887.html


1887.    Copier Reduction
Time Limit: 1.0 Seconds    Memory Limit: 65536K
Total Runs: 1123    Accepted Runs: 724



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 ABC, 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.

Example input:Example output:
560 400 218 280
10 25 88 10
8 13 5 1
9 13 10 6
199 333 40 2
75 90 218 280
999 99 1 10
0 0 0 0
50%
100%
12%
66%
1%
100%
1%


Source: Mid-Central USA 2005
Submit   List    Runs   Forum   Statistics

#include <stdio.h>
#include <algorithm>
#define swap(a,b){a=a+b;b=a-b;a=a-b;}
int main(){
	int a,b,c,d;
	while(~scanf("%d%d%d%d",&a,&b,&c,&d),a*b*c*d){
		if(a<b) swap(a,b);
		if(c<d) swap(c,d);
		if(a<=c&&b<=d)
			printf("100%%\n");
		else
			printf("%d%%\n",(int)(100*std::min((1.0*d/b),(1.0*c/a))));
	}
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值