Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0
最大面积是2*n*n
面积为2*n*n+n-1
面积为2*n*n+2*n
面积为2*n*n+3*n
所以每询问一个s,只要从4开始循环找到一个最小的n使的面积大于s就行。
1 #include <iostream> 2 #include <stdio.h> 3 #include <string.h> 4 #include <vector> 5 #include <map> 6 #include <set> 7 #define ll long long 8 using namespace std; 9 ll solve(ll y) { 10 ll n = y / 4, ans = y % 4, x; 11 if(ans == 0) { 12 x = 2*n*n; 13 }else if(ans == 1) { 14 x = 2*n*n+n-1; 15 }else if(ans == 2) { 16 x = 2*n*n+2*n; 17 }else if(ans == 3) { 18 x = 2*n*n+3*n; 19 } 20 return x; 21 } 22 int main() { 23 ll t, x; 24 scanf("%lld", &t); 25 while(t--) { 26 scanf("%lld", &x); 27 for(ll i = 4; ; i ++) { 28 if(solve(i) >= x) { 29 printf("%lld\n",i); 30 break; 31 } 32 } 33 } 34 return 0; 35 }
原文:http://www.cnblogs.com/xingkongyihao/p/7397373.html