CCPC2017网络赛1005 CaoHaha's staff——找规律

时间:2022-12-20 23:26:25



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

给定面积s,找比他小的那个菱形(正方形),然后找面积增加的规律,计算s在哪个区间

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
using namespace std;
typedef long long ll;
int main() {
    int T; scanf("%d", &T);
    while (T--) {
        ll s; scanf("%I64d", &s);
        ll n = sqrt(1.0 * s) / sqrt(2.0);
        ll s1 = 2 * n * n;
        if (s == s1) {
            printf("%I64d\n", 4 * n);
        }
        else if (s1 < s && 2 * s <= 2 * s1 + (2*n-1)) {
            printf("%I64d\n", 4 * n + 1);
        }
        else if (2 * s1 + (2*n-1) < 2 * s && 2 * s <= 2 * s1 + 4*n) {
            printf("%I64d\n", 4 * n + 2);
        }
        else if (2 * s1 + 4*n < 2 * s && 2 * s <= 2 * s1 + (6*n+1)) {
            printf("%I64d\n", 4 * n + 3);
        }
        else if (2 * s1 + (6*n+1) < 2 * s && 2 * s <= 2 * s1 + (8*n+4)) {
            printf("%I64d\n", 4 * n + 4);
        }
    }
    return 0;
}