CaoHaha's staff
Posted #忘乎所以#
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CaoHaha's staff相关的知识,希望对你有一定的参考价值。
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.
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
题目好魔性,就是画图,使劲画图,找规律.
然后打表,然后就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的主要内容,如果未能解决你的问题,请参考以下文章
HDU 6154 CaoHaha's staff 思维 找规律
2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6154 CaoHaha's staff(几何找规律)