标签:wan vector can Owner diagonal app 竞赛 number magic
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<vector> 6 #include<queue> 7 #include<algorithm> 8 using namespace std; 9 10 int main() 11 { 12 int T; 13 scanf("%d",&T); 14 while(T--) 15 { 16 double s; 17 scanf("%lf",&s); 18 int d=sqrt(s); 19 int ans; 20 if(2*d*d>=s) 21 ans=d*4; 22 else if(2*d*d+d-0.5>=s) 23 ans=d*4+1; 24 else if(2*d*d+2*d>=s) 25 ans=4*d+2; 26 else 27 ans=4*d+3; 28 bool flag; 29 while(ans>=3) 30 { 31 d=ans/4; 32 flag=false; 33 if(ans%4==0){ 34 if((double)(2*d*d)>=s) 35 flag=true; 36 } 37 else if(ans%4==1){ 38 if((double)(2*d*d+d-0.5)>=s) 39 flag=true; 40 } 41 else if(ans%4==2){ 42 if((double)(2*d*d+2*d)>=s) 43 flag=true; 44 } 45 else if(ans%4==3){ 46 if((double)(2*d*d+3*d+0.5)>=s) 47 flag=true; 48 } 49 if(flag) 50 ans--; 51 else 52 { 53 printf("%d\n",ans+1); 54 break; 55 } 56 } 57 } 58 return 0; 59 }
2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6154 CaoHaha's staff(几何找规律)
标签:wan vector can Owner diagonal app 竞赛 number magic
原文地址:http://www.cnblogs.com/Annetree/p/7403973.html