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. Matlab-11:Gausssidel迭代法工具箱

    算法推导: function [u,n]=GaussSeid(A,b,u0,eps,M) %GaussSeid.m为用高斯-塞德尔迭代法求解线性方程组 %A为线性方程组的系数矩阵 %b为线性方程组的常 ...

  2. 【Oracle】【3】字段自增长(+1)

    业务场景——解决方案 1,每插入一条数据,其排序字段要增长1 —— Service层查询出最大值,再+1(参考博客的方法是触发器) 2,子表插入一条数据,主表某字段+1 —— where A.ID = ...

  3. python-爬虫-Beautifulsoup模块

    一 介绍 Beautiful Soup 是一个可以从HTML或XML文件中提取数据的Python库.它能够通过你喜欢的转换器实现惯用的文档导航,查找,修改文档的方式.Beautiful Soup会帮你 ...

  4. Java异常及错误

    java提供了两种异常机制,可以分为运行时异常(RuntimeException)与检查式异常(checked Exception). 检查式异常:java编译器对于这种异常需要我们对其用try... ...

  5. git push 失败出现error: src refspec master does not match any.解决方案

    今天写好一个demo往GitHub上传时报错 错误提示: error: src refspec master does not match any. error: failed to push som ...

  6. SQL 查询语句

    4.2 单表查询 4.2.1 列名(表名)的别名(as 可以不加) 给列名取别名既可以加 as 也可以不加. (2008 - Sage.lower(Sdept)等可计算但无列名,需要指定列名) 原列名 ...

  7. MapReduce(一)

    MapReduce(一) 一.介绍 百度百科: MapReduce是一种编程模型,用于大规模数据集(大于1TB)的并行运算.概念"Map(映射)"和"Reduce(归约) ...

  8. Eclipse错误:The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path

    该报错是由于缺少servlet-api.jar造成的,将servlet-api.jar复制到项目下的WEB-INF/lib目录下即可 servlet-api.jar在tomcat的lib目录下有,可以 ...

  9. EventBus简单封装

    前言 以前每个页面与每个页面业务逻辑传递让你不知所措,一个又一个接口回调,让你晕头转向,一个又一个参数让你混乱不堪.EventBus一个耦合度低的让你害怕的框架. 什么是EventBus EventB ...

  10. windows中mysql5.7保存emoji表情

    1.找到my.ini文件,修改一下配置: [client] default-character-set=utf8mb4 [mysqld] character-set-client-handshake ...