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

CaoHaha's staff

时间:2017-08-19 18:48:50      阅读:219      评论:0      收藏:0      [点我收藏+]

标签:ast   bre   inf   mis   with   using   val   integer   power   

CaoHaha‘s staff

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0


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
题目好魔性,就是画图,使劲画图,找规律.
然后打表,然后就A了.
 1 #include <bits/stdc++.h>
 2 #define ll long long int
 3 #define N 1000005
 4 using namespace std;
 5 int k[N];
 6 void fa(){
 7     memset(k,0,sizeof(k));
 8     k[0]=k[1]=0;
 9     for(int i=2;i<N;i++){
10         if(i%2==0){
11             k[i]=i/4*2+k[i-2];
12         }else{
13             k[i]=(i+1)/4+k[i-1]-1;
14         }
15     }
16 }
17 int main(){
18     int n;
19     fa();
20     scanf("%d",&n);
21     while(n--){
22         int x;
23         scanf("%d",&x);
24         for(int i=0;i<N;i++){
25             if(k[i]>=x){
26                 printf("%d\n",i);
27                 break;
28             }
29         }
30     }
31     return 0;
32 }

 

CaoHaha's staff

标签:ast   bre   inf   mis   with   using   val   integer   power   

原文地址:http://www.cnblogs.com/zllwxm123/p/7397280.html

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