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
 
题意:画出给出面积至少需要几笔
题解:逆着推几笔最多能画出多少面积
可以发现有四种情况。n为画的笔数,d=[n/4];
1.n%4==0 刚好可以画一个正方形(边全在对角线上) 面积为2*d*d
2.n%4==2 可以在正方形基础上将较短边扩展,增加面积是较长边*1 面积为 2*d*d+2*d
3.n%4==1 可以在矩形基础上加上长边-0.5(即在较短边上扩展一个梯形,梯形是2中添加的矩形缺一个角)面积为2*d*d+d-0.5
4.n%4==3 同3 面积为2*d*d+3*d+0.5
然后逆着 运算即可
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std; int main()
{
int T;
scanf("%d",&T);
while(T--)
{
double s;
scanf("%lf",&s);
int d=sqrt(s);
int ans;
if(*d*d>=s)
ans=d*;
else if(*d*d+d-0.5>=s)
ans=d*+;
else if(*d*d+*d>=s)
ans=*d+;
else
ans=*d+;
bool flag;
while(ans>=)
{
d=ans/;
flag=false;
if(ans%==){
if((double)(*d*d)>=s)
flag=true;
}
else if(ans%==){
if((double)(*d*d+d-0.5)>=s)
flag=true;
}
else if(ans%==){
if((double)(*d*d+*d)>=s)
flag=true;
}
else if(ans%==){
if((double)(*d*d+*d+0.5)>=s)
flag=true;
}
if(flag)
ans--;
else
{
printf("%d\n",ans+);
break;
}
}
}
return ;
}

2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6154 CaoHaha's staff(几何找规律)的更多相关文章

  1. 2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6154 CaoHaha's staff 思维

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6154 题意:在笛卡尔坐标系下,画一个面积至少为  n 的简单多边形,每次只能画一条边或者一个格子的对角 ...

  2. 【2017中国大学生程序设计竞赛 - 网络选拔赛 && hdu 6154】CaoHaha's staff

    [链接]点击打开链接 [题意] 给你一个面积,让你求围成这个面积最少需要几条边,其中边的连线只能是在坐标轴上边长为1的的线或者是两个边长为1 的线的对角线. [题解] 找规律题 考虑s[i]表示i条边 ...

  3. 2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6155 Subsequence Count 矩阵快速幂

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6155 题意: 题解来自:http://www.cnblogs.com/iRedBean/p/73982 ...

  4. 2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6152 Friend-Graph(暴力搜索)

    题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=6152 Problem Description It is well known that small ...

  5. 2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6150 Vertex Cover 二分图,构造

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6150 题意:"最小点覆盖集"是个NP完全问题 有一个近似算法是说—每次选取度数最大 ...

  6. 2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6152 Friend-Graph 暴暴暴暴力

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6152 题意:判定一个无向图是否有三个点的团或者三个点的独立集. 解法:Ramsey theorem,n ...

  7. 2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6153 A Secret KMP,思维

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6153 题意:给了串s和t,要求每个t的后缀在在s中的出现次数,然后每个次数乘上对应长度求和. 解法:关 ...

  8. 2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6156 数位DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6156 题意:如题. 解法:数位DP,暴力枚举进制之后,就转化成了求L,R区间的回文数的个数,这个直接做 ...

  9. 【2017中国大学生程序设计竞赛 - 网络选拔赛 hdu 6150】Vertex Cover

    [链接]点击打开链接 [题意] 有人写了一个最小点覆盖的贪心算法,然后,让你去hack它. 并且,要求这个算法得到的错误答案,是正确答案的三倍. 让你任意输出hack数据,点数<=500 [题解 ...

随机推荐

  1. php多线程代码

    <?php$thNum = 20; //20个进程$total = 20000;//总数$pageNum=100;//每个页面显示100条数据 $pageCount = ceil($total/ ...

  2. Oracle 11.2.0.4.0 Dataguard部署和日常维护(3)-Datauard监控篇

    1.  v$database    查看当前数据库的角色和保护模式 primary库查看 column NAME format a10 column PROTECTION_MODE format a2 ...

  3. 一、ZooKeeper学习

    一.什么是ZooKeeper? ZooKeeper是一个分布式应用的开源协调服务.目的就是给用户提供同步.配置管理.分组和命名等服务.是Java语言编写的,支持Java和C两种语言.通俗的讲,它就是用 ...

  4. Eclipse集成weblogic教程

    1.在线安装插件 1.1安装Oracle Weblogic Servers Tools oeop是添加的软件仓库的名字,随便写主要是方便记. 仓库链接:http://www.oracle.com/te ...

  5. 套接字编程,建立连接connect,绑定套接字bind

    1.建立连接 int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen); 参数sockfd是由函数socket创建 ...

  6. hibernate配置log

    hibernate依赖jboss-logging,通过它选择对应的对应的日志包,选择的逻辑课查看具体代码org.jboss.logging.LoggerProviders. 先通过系统变量(org.j ...

  7. 转Generative Model 与 Discriminative Model

    没有完全看懂,以后再看,特别是hmm,CRF那里,以及生成模型产生的数据是序列还是一个值,hmm应该是序列,和图像的关系是什么. [摘要]    - 生成模型(Generative Model) :无 ...

  8. H5 PWA技术以及小demo

    H5 PWA技术 1.原生app优缺点 a.体验好.下载到手机上入口方便 b.开发成本高(ios和安卓) c.软件上线需要审核 d.版本更新需要将新版本上传到不同的应用商店 e.使用前需下载 2.we ...

  9. weblogic相关

    来源:http://zhidao.baidu.com/link?url=gqPaYovGiEHYPPPyI6PgPV6THVLr4nlj3CGCjY3mwm0-ERUnfuQz614ywAwYLnP6 ...

  10. 容错机制和熔断(Hystrix)

    雪崩效应 在微服务架构中,由于服务众多,通常会涉及多个服务层级的调用,而一旦基础服务发生故障,很可能会导致级联故障,进而造成整个系统不可用,这种现象被称为服务雪崩效应.服务雪崩效应是一种因“服务提供者 ...