POJ 2707 Copier Reduction

問題
http://poj.org/problem?id=2707

解法
ほとんどやるだけ
両方とも横長か縦長に揃えて考えるといい。
あとは場合分けを気をつける

#include <cstdio>
#include <algorithm>
using namespace std;

int x1, y1, x2, y2;
void swap(int *a, int *b){
	int t;
	t = *a;
	*a = *b;
	*b = t;
}
int main(){
	while(scanf("%d %d %d %d", &x1, &y1, &x2, &y2) && x1 != 0){
		if(x1 > y1) swap(&x1, &y1);
		if(x2 > y2) swap(&x2, &y2);
		double rx, ry;
		rx=(double)x2/(double)x1; ry=(double)y2/(double)y1;
		//printf("%lf %lf\n", rx,ry);
		int p;
		if(rx * y1 <= y2 && ry * x1 <= x2){
			p = (int)(max(rx,ry)*100.0);
		}else if(rx * y1 <= y2){
			p = (int)(rx*100.0);
		}else{
			p = (int)(ry*100.0);
		}
		printf("%d%%\n", p>100?100:p);
	}
	return 0;
}