2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6154 CaoHaha's staff(几何找规律)
Posted Annetree的博客
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6154 CaoHaha's staff(几何找规律)相关的知识,希望对你有一定的参考价值。
Problem Description
"You shall not pass!"
After shouted out that,the Force Staff appered in CaoHaha‘s hand.
As we all know,the Force Staff is a staff with infinity power.If you can use it skillful,it may help you to do whatever you want.
But now,his new owner,CaoHaha,is a sorcerers apprentice.He can only use that staff to send things to other place.
Today,Dreamwyy come to CaoHaha.Requesting him send a toy to his new girl friend.It was so far that Dreamwyy can only resort to CaoHaha.
The first step to send something is draw a Magic array on a Magic place.The magic place looks like a coordinate system,and each time you can draw a segments either on cell sides or on cell diagonals.In additional,you need 1 minutes to draw a segments.
If you want to send something ,you need to draw a Magic array which is not smaller than the that.You can make it any deformation,so what really matters is the size of the object.
CaoHaha want to help dreamwyy but his time is valuable(to learn to be just like you),so he want to draw least segments.However,because of his bad math,he needs your help.
After shouted out that,the Force Staff appered in CaoHaha‘s hand.
As we all know,the Force Staff is a staff with infinity power.If you can use it skillful,it may help you to do whatever you want.
But now,his new owner,CaoHaha,is a sorcerers apprentice.He can only use that staff to send things to other place.
Today,Dreamwyy come to CaoHaha.Requesting him send a toy to his new girl friend.It was so far that Dreamwyy can only resort to CaoHaha.
The first step to send something is draw a Magic array on a Magic place.The magic place looks like a coordinate system,and each time you can draw a segments either on cell sides or on cell diagonals.In additional,you need 1 minutes to draw a segments.
If you want to send something ,you need to draw a Magic array which is not smaller than the that.You can make it any deformation,so what really matters is the size of the object.
CaoHaha want to help dreamwyy but his time is valuable(to learn to be just like you),so he want to draw least segments.However,because of his bad math,he needs your help.
Input
The first line contains one integer T(T<=300).The number of toys.
Then T lines each contains one intetger S.The size of the toy(N<=1e9).
Then T lines each contains one intetger S.The size of the toy(N<=1e9).
Output
Out put T integer in each line ,the least time CaoHaha can send the toy.
Sample Input
5
1
2
3
4
5
Sample Output
4
4
6
6
7
题意:画出给出面积至少需要几笔
题解:逆着推几笔最多能画出多少面积
可以发现有四种情况。n为画的笔数,d=[n/4];
1.n%4==0 刚好可以画一个正方形(边全在对角线上) 面积为2*d*d
2.n%4==2 可以在正方形基础上将较短边扩展,增加面积是较长边*1 面积为 2*d*d+2*d
3.n%4==1 可以在矩形基础上加上长边-0.5(即在较短边上扩展一个梯形,梯形是2中添加的矩形缺一个角)面积为2*d*d+d-0.5
4.n%4==3 同3 面积为2*d*d+3*d+0.5
然后逆着 运算即可
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(几何找规律)的主要内容,如果未能解决你的问题,请参考以下文章
2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6154 CaoHaha's staff(几何找规律)
2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6156 数位DP
2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6155 Subsequence Count 矩阵快速幂