题目:给你很多张矩形的纸,问哪张可以剪下四个面积相同的最大的正方形。
分析:简单题。只有两种减法:1.剪成2*2的;2.剪成1*4的。
注意:计算后的正方形边长可能是小数,例如:2*2的比3*3的小,要用浮点型处理。
#include <iostream>
#include <cstdlib>
#include <cstdio>
using namespace std;
double value( int h, int w )
{
if ( h < w ) swap( h, w );
return max( w/2.0, min( h/4.0, w+0.0 ) );
}
int main()
{
int n;
int h,w;
while ( ~scanf("%d",&n) && n ) {
double max = 0,now = 1;
for ( int i = 1 ; i <= n ; ++ i ) {
scanf("%d%d",&h,&w);
if ( max < value( h, w ) ) {
max = value( h, w );
now = i;
}
}
printf("%.0lf\n",now);
}
return 0;
}