题目链接:Tom and paper
题面:
3 2 7 12
6 16 14
解题:
若周长固定,取半值附近的值,面积最大。反之,取平方根附近,周长最长。
代码:
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int t,n,root;
cin>>t;
while(t--)
{
cin>>n;
root=sqrt(1.0*n);
for(int i=root;;i--)
{
if(n%i==0)
{
cout<<2*(i+n/i)<<endl;
break;
}
}
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
HDU 5224 Tom and paper(BestCoder Round #40)
原文:http://blog.csdn.net/david_jett/article/details/46780405