CaoHaha's staff

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

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
 
Source
Recommend
liuyiding   |   We have carefully selected several similar problems for you:  6160 6159 6158 6157 6156 
 

题意:

一笔可以画一条长为1的边或者一条根号二的对角线,问围成一个面积是n 的图形最少需要几条边

题解:

找规律画图

这题可以先把问题转化为已知画m笔,最大可以画出多大的面积

当m%4==0,画sqrt(2)的边,可以达成最大的面积

当m%4==1,就把[m/4]*4围成的图像的 最长边往外推sqrt(2)/2,比原来增加一个梯形的面积

当m%4==2,就把[m/4]*4围成的图像的 最长边往外推sqrt(2)长度,增加一个小矩形面积

当m%4==3,在m%4==2的基础上实行m%4==1一样的操作

#include <iostream>
#include<bits/stdc++.h>
using namespace std; int t;
int n,sd; int sumS(int m) //m是周长,推出公式就可以了
{
int d=m/;
if (m%==) return *d*d;
if (m%==) return *d*d+d-;
if (m%==) return *d*d+*d;
if (m%==) return *d*d+*d;
}
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
sd=(int)sqrt(n/2.0)*; //最小的周长
while()
{
if (sumS(sd)>=n) {printf("%d\n",sd); break;}
sd++;
}
}
return ;
}

hdu 6154 CaoHaha's staff的更多相关文章

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

    /* HDU 6154 - CaoHaha's staff [ 构造,贪心 ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛 题意: 整点图,每条线只能连每个方格的边或者对角线 问面积大于n的 ...

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

    题目代号:HDU 6154 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6154 CaoHaha's staff Time Limit: 2000/1 ...

  3. 2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6154 CaoHaha's staff(几何找规律)

    Problem Description "You shall not pass!"After shouted out that,the Force Staff appered in ...

  4. 2017中国大学生程序设计竞赛 - 网络选拔赛 1005 HDU 6154 CaoHaha's staff (找规律)

    题目链接 Problem Description "You shall not pass!" After shouted out that,the Force Staff appe ...

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

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

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

    Problem Description "You shall not pass!" After shouted out that,the Force Staff appered i ...

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

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

  8. 【推导】【找规律】【二分】hdu6154 CaoHaha's staff

    题意:网格图.给你一个格点多边形的面积,问你最少用多少条边(可以是单位线段或单位对角线),围出这么大的图形. 如果我们得到了用n条边围出的图形的最大面积f(n),那么二分一下就是答案. n为偶数时,显 ...

  9. HDU6154

    CaoHaha's staff Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

随机推荐

  1. D. Babaei and Birthday Cake---cf629D(LIS线段树优化)

    题目链接:http://codeforces.com/problemset/problem/629/D 题意就是现有n个蛋糕,蛋糕的形状是圆柱体,每个蛋糕的体积就是圆柱体的体积,每个蛋糕的编号是1-- ...

  2. Network---3694poj(桥与LCA)

    题目链接 题意: 有n个电脑1-n,m个连接,由于可能存在一些桥,如果这些桥出现了问题,那么会导致一些电脑之间无法连接,   所以建立链接Q次,每次链接a和b电脑,求链接ab后还存在几个桥:   如果 ...

  3. Python知识总汇

    一.python基础 python基础 python编码问题 逻辑运算 二.python数据类型 二.python数据类型 三.IO(文件处理) 三.IO(文件处理) 四.函数 函数基础 名称空间与作 ...

  4. Python 读取写入配置文件 —— ConfigParser

    Python 读取写入配置文件 —— ConfigParser Python 读取写入配置文件很方便,可使用内置的 configparser 模块:可查看源码,如博主本机地址: “C:/python2 ...

  5. 模块讲解----XML模块

    XML实现不同语言或者程序之间进行数据交换的协议XML文件格式如下: 1.浏览器返回的字符串格式类型有: a.HTML b.Json c.XML 2.XML格式如下: <data> #表示 ...

  6. 牛客国庆集训派对Day6 Solution

    A    Birthday 思路:设置一个源点,一个汇点,每次对$源点对a_i, b_i , a_i 对 b_i 连一条流为1,费用为0的边$ 每个点都再连一条 1, 3, 5, 7, ....的边到 ...

  7. javascript数组总结

    数组是一个有序的集合,javascript数组中的元素的类型可以是任意的,同一个数组不同元素之间的类型也是可以不同的.数组也是对象,有个length属性,记录数组的长度. 创建数组有两种方法: 数组直 ...

  8. 【转】微信jssdk录音功能开发记录

    转自:http://www.cnblogs.com/liujunyang/p/4962423.html#undefined 0.需求描述 在微信浏览器内打开的页面,制作一个按钮,用户按住按钮后开始录音 ...

  9. Web安全之BurpSuite抓取HTTPS请求

    出现了问题,第一步要干什么呢? 当然是要去官方网站去找FAQ和help,先来练习一下英语 https://portswigger.net/burp/help/proxy_options_install ...

  10. 【建项目】eclipse maven建立多模块工程

    在工作的时候,大多时候都是用Maven来管理项目,可是一般我们都知道怎么用maven管理工程,却不知道通过Maven自己来建立多模块工程.于是自己抽时间,在网上找些资料,做了起来. 建立简单的Mave ...