51Nod 1283 最小周长
Problem Description
一个矩形的面积为S,已知该矩形的边长都是整数,求所有满足条件的矩形中,周长的最小值。例如:S = 24,那么有{1 24} {2 12} {3 8} {4 6}这4种矩形,其中{4 6}的周长最小,为20。
Input
输入1个数S(1 <= S <= 10^9)。
Output
输出最小周长。
Sample Input
24
Sample Output
20
题解思路:
矩形面积一定时,长宽相差越小,周长越小。
1 #include <bits/stdc++.h> 2 using namespace std; 3 const int MAXN = 10005; 4 const int INF = 1e9+7; 5 6 int main() 7 { 8 int s,a,b; 9 scanf("%d",&s); 10 a = sqrt(s)+0.5; 11 while(1) 12 { 13 if(s%a == 0) 14 { 15 b = s/a; 16 break; 17 } 18 a--; 19 } 20 printf("%d\n",2*(a+b)); 21 return 0; 22 }