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. django的crontab

    最近需要考虑如何在django环境中跑定时任务. 这个在  stackoverflow 也有对应的 讨论 , 方法也有不少, 这边简单尝试和总结下. 假设我们现在的定期任务就是睡眠  n 秒, 然后往 ...

  2. 安装Ruby、Sass在WebStrom添加Watcher实现编辑scss文件时自动生成.map和压缩后的.css文件

    前言 这段时间一直在看Bootstrap,V3官方直接提供了Less版本的源码,就先将Less学完了,很简单的语法,学习写Demo都是在Webstorm里写的,配置了Watcher自动编译(详见< ...

  3. HTTP错误 404.17–Not Found 请求的内容似乎是脚本,因而将无法有静态文件处理程序来处理

    解决方案:切换应用程序池的模式.

  4. Windows上的巧克力味Chocolatey详解

    Chocolatey是什么?很简单,Chocolatey就是Windows系统的yum或apt-get. 一.Chocolatey介绍 Chocolatey是一款专为Windows系统开发的.基于Nu ...

  5. Spark提交应用程序之Spark-Submit分析

    1.提交应用程序 在提交应用程序的时候,用到 spark-submit 脚本.我们来看下这个脚本: if [ -z "${SPARK_HOME}" ]; then export S ...

  6. openSession()与getCurrentSession()的区别

    getCurrentSession创建的session会和绑定到当前线程,而openSession不会. getCurrentSession创建的线程会在事务回滚或事物提交后自动关闭,而openSes ...

  7. poj1673 EXOCENTER OF A TRIANGLE

    地址:http://poj.org/problem?id=1673 题目: EXOCENTER OF A TRIANGLE Time Limit: 1000MS   Memory Limit: 100 ...

  8. EF Code First 学习笔记:表映射(转)

      多个实体映射到一张表 Code First允许将多个实体映射到同一张表上,实体必须遵循如下规则: 实体必须是一对一关系 实体必须共享一个公共键 观察下面两个实体: public class Per ...

  9. 使用ffmpeg进行网络直播

    一.采集:使用python调用摄像头采集,原设想是使用树莓派摄像头采集,但是经费紧张买不起,先用摄像头凑合下,反正很简单.                   原理就是先录一小段视频,然后循环播放,用 ...

  10. 通过自动回复机器人学Mybatis:MySQL脚本 + db >> dao >> service >> servlet

    留着参考 makeData.sql delimiter // create procedure make_data() begin declare i int ; do insert into mes ...