2017ccpc網賽-1005-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.

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

ac代碼,找規律
題意:走最小的步數圍成的最大面積不小於s

#include"iostream"
#include"math.h"
using namespace std;

int main()
{
    int T;
    int ai[20];
    ai[1]=4;    ai[2]=4;    ai[3]=6;    ai[4]=6;    ai[5]=7;
    ai[6]=8;    ai[7]=8;     ai[8]=8;    ai[9]=9;    ai[10]=9;    
    ai[11]=10;    ai[12]=10;    ai[13]=11;    ai[14]=11;    ai[15]=11;    
    ai[16]=12;    ai[17]=12;    ai[18]=12;    ai[19]=13;
    cin>>T;
    while(T--)
    {
        int n;
        scanf("%d",&n);
        if(n<20) cout<<ai[n]<<endl;
        else
        {
            int r=sqrt(n/2);
            int center=r*r*2;
            int gen=r*4;
            if(n==center)  cout<<gen<<endl;
            else if(n-center<=r)    cout<<gen+1<<endl;
            else if(n-center<=r*2)    cout<<gen+2<<endl;
            else if(n-center<=3*r+1)    cout<<gen+3<<endl;
            else    cout<<gen+4<<endl;
        }
    }
    return 0;
 } 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章