CaoHaha's staff (HDU 6154)(2017中国大学生程序设计竞赛 - 网络选拔赛)
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
题解:题目要求画的线段必须是边或者对角线,并且边的长度是1,对角线的长度是2^(1/2)(根号2),让用最少的线段来画出可以满足的面积。因为2^(1/2)要长,所以可以多画对角线,少画边,那么画出图形在面积小于8的时候是特殊情况,如果大于8,才会出现规律,按照画菱形的方法(以一开始是2条对角线构成的菱形为例),每次加一条线,可以增加面积1.5,增加两条线,这两条线又可以合并,面积增加2.5,增加三条线,面积增加2.5,增加4条线,也就又构成了一个新的正方形,面积在三条线的基础上又增加了3.5。所以只要找到能够符合面积的范围,在这个基础上选择增加的线即可。

(图片截自http://www.cnblogs.com/teble/p/7425292.html,如有侵权,立即删除)。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll t, n;
scanf("%lld",&t);
while(t--)
{
scanf("%lld",&n);
if(n==1||n==2)printf("4\n");
else if(n==3||n==4) printf("6\n");
else if(n==5) printf("7\n");
else if(n>=6&&n<=8) printf("8\n");
else
{
long long m = floor(sqrt(n/2));
long long ans = m*4;
long long x=m*m*2;
if(n==x)printf("%lld\n", ans);
else if(n<=x+m-0.5)printf("%lld\n", ans + 1);
else if(n<=x+2*m)printf("%lld\n", ans + 2);
else if(n<=3*m+0.5+x)printf("%lld\n", ans + 3);
else printf("%lld\n", ans + 4);
}
}
return 0;
}
CaoHaha's staff (HDU 6154)(2017中国大学生程序设计竞赛 - 网络选拔赛)的更多相关文章
- Friend-Graph (HDU 6152)2017中国大学生程序设计竞赛 - 网络选拔赛
Problem Description It is well known that small groups are not conducive of the development of a tea ...
- HDU 6154 - CaoHaha's staff | 2017 中国大学生程序设计竞赛 - 网络选拔赛
/* HDU 6154 - CaoHaha's staff [ 构造,贪心 ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛 题意: 整点图,每条线只能连每个方格的边或者对角线 问面积大于n的 ...
- HDU 6154 CaoHaha's staff(2017中国大学生程序设计竞赛 - 网络选拔赛)
题目代号:HDU 6154 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6154 CaoHaha's staff Time Limit: 2000/1 ...
- HDU 6150 - Vertex Cover | 2017 中国大学生程序设计竞赛 - 网络选拔赛
思路来自 ICPCCamp /* HDU 6150 - Vertex Cover [ 构造 ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛 题意: 给了你一个贪心法找最小覆盖的算法,构造一组 ...
- HDU 6156 - Palindrome Function [ 数位DP ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛
普通的数位DP计算回文串个数 /* HDU 6156 - Palindrome Function [ 数位DP ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛 2-36进制下回文串个数 */ ...
- 2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6154 CaoHaha's staff(几何找规律)
Problem Description "You shall not pass!"After shouted out that,the Force Staff appered in ...
- 2017中国大学生程序设计竞赛 - 网络选拔赛 1005 HDU 6154 CaoHaha's staff (找规律)
题目链接 Problem Description "You shall not pass!" After shouted out that,the Force Staff appe ...
- 2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6154 CaoHaha's staff 思维
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6154 题意:在笛卡尔坐标系下,画一个面积至少为 n 的简单多边形,每次只能画一条边或者一个格子的对角 ...
- 【2017中国大学生程序设计竞赛 - 网络选拔赛 && hdu 6154】CaoHaha's staff
[链接]点击打开链接 [题意] 给你一个面积,让你求围成这个面积最少需要几条边,其中边的连线只能是在坐标轴上边长为1的的线或者是两个边长为1 的线的对角线. [题解] 找规律题 考虑s[i]表示i条边 ...
随机推荐
- Java 私有构造函数的使用
被private修饰的私有构造函数无法在其他类中调用,也就是该类无法在其他类中实例化. 这种情况常用的使用场景:1.单例模式: 2.防止实例化. 一.单例模式 单例模式是一种常用的设计模式,思想是单例 ...
- Sql Server 收缩日志文件原理及always on 下的实践
一.准备知识 1.LSN LSN用来标识特定日志在日志文件中位置(详情请见什么是LSN:日志序列号),它由两部分组成:一部分用来标识VLF(虚拟日志文件)的序列号,剩下的用来标识该日志在VLF中的具体 ...
- oracle索引查询
/*<br>* *查看目标表中已添加的索引 * */ --在数据库中查找表名 select * from user_tables where table_name like 'table ...
- JAVA实现QQ聊天气泡
最近做了聊天气泡功能,为自己的聊天室美化了一下聊天效果: 先来看一下效果: 主要的思路是:以一个JTextPane作为显示的面板,然后自定义一个组件JBubble气泡组件来实现他的聊天气泡,然后通过J ...
- Bootstrap treegrid 实现树形表格结构
前言 :最近的项目中需要实现树形表格功能,由于前端框架用的是bootstrap,但是bootstrapTable没有这个功能所以就找了一个前端的treegrid第三方组件进行了封装.现在把这个封装的组 ...
- sed原理及sed命令格式 ,缓存区,模式空间
4.1 Sed工作原理 sed是一个非交互式的流编辑器.所谓非交互式,是指使用sed只能在命令行下输入编辑命令来编辑文本,然后在屏幕上查看输出:而所谓流编辑器,是指sed每次只从 ...
- zip命令分卷压缩和解压缩
创建分卷压缩文件 zip -s 100m -r folder.zip folder/ -s: 创建分卷的大小 -r: 循环压缩文件夹下面的内容 切分已有的文件: zip existing.zip -- ...
- STM32L1xx——sx1278开发之LoRa扩频技术基础知识
扩频技术的发现 1944年,好莱坞26岁女影星HedyLamarr(号称世界上最美丽的女人)发明了扩频通信技术,这种跳频技术可以有效地抗击干扰和实现加密. 后来人们发现,扩频技术可以得到如下收益:从各 ...
- Fiddler抓包HTTPS捕捉旧版App
“现在可以公开的情报:简易操作Fiddler抓包可能” 任何App的更新都限于苹果开发者规定,有时为了上架不得已放弃一些真正实用的功能,比如视频音频的直接下载,脚本的直接导入,手机上IPA的直接安装等 ...
- mongo批量写入es
import pymongo import math from elasticsearch import Elasticsearch from elasticsearch import helpers ...