HDU6154-CaoHaha's staff

来源:互联网 发布:数据透视表多条件筛选 编辑:程序博客网 时间:2024/05/16 06:28

CaoHaha's staff

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


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
512345
 

Sample Output
44667
 

Source
2017中国大学生程序设计竞赛 - 网络选拔赛
 


题意:在一个二维坐标系中,给你一个整数面积 S ,让你用尽量少的边围出一个封闭图形,使得该图形的面积大于等于 S 。每条边可以是长为 1 的平行或垂直于坐标轴的线段或者斜率为 1 或 -1 长为sqrt(2)的线段

解题思路:应该优先选择菱形扩展,先在其一侧可以通过添加一条边,这样就可以在其这一侧增加的面积为菱形边长/sqrt(2)-0.5。当扩展的边数大于等于二的时候,就会出现空余的三角形,这样就可以通过不增加边使面积再增加1。边数较小的情况需要特判
2的线段


#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <map>#include <set>#include <stack>#include <queue>#include <vector>#include <bitset>#include <functional>using namespace std;#define LL long longconst int INF = 0x3f3f3f3f;LL n;int a[10] = { 0,4,4,6,6,7,8,8,8 };int main(){    int t;    scanf("%d", &t);    while (t--)    {        scanf("%lld", &n);        if (n <= 8) { printf("%d\n", a[n]); continue; }        LL k = (LL)sqrt(1.0*n / 2);        LL ans = k * 4, m = 2 * k*k;        if (n == m) printf("%lld\n", ans);        else if (n <= m + k - 1) printf("%lld\n", ans + 1);        else if (n <= m + k * 2) printf("%lld\n", ans + 2);        else if (n <= m + k * 3 - 1) printf("%lld\n", ans + 3);        else printf("%lld\n", ans + 4);    }    return 0;}