码迷,mamicode.com
首页 > 其他好文 > 详细

2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6154 CaoHaha's staff(几何找规律)

时间:2017-08-21 13:59:38      阅读:250      评论:0      收藏:0      [点我收藏+]

标签:wan   vector   can   Owner   diagonal   app   竞赛   number   magic   

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.
 

 

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).
 

 

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(几何找规律)

标签:wan   vector   can   Owner   diagonal   app   竞赛   number   magic   

原文地址:http://www.cnblogs.com/Annetree/p/7403973.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!