HDU6154-CaoHaha's staff
来源:互联网 发布:数据透视表多条件筛选 编辑:程序博客网 时间:2024/05/16 06:28
CaoHaha's staff
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 561 Accepted Submission(s): 332
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.
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).
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
512345
Sample Output
44667
Source
2017中国大学生程序设计竞赛 - 网络选拔赛
题意:在一个二维坐标系中,给你一个整数面积 S ,让你用尽量少的边围出一个封闭图形,使得该图形的面积大于等于 S 。每条边可以是长为 1 的平行或垂直于坐标轴的线段或者斜率为 1 或 -1 长为sqrt(2)的线段
解题思路:应该优先选择菱形扩展,先在其一侧可以通过添加一条边,这样就可以在其这一侧增加的面积为菱形边长/sqrt(2)-0.5。当扩展的边数大于等于二的时候,就会出现空余的三角形,这样就可以通过不增加边使面积再增加1。边数较小的情况需要特判
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <map>#include <set>#include <stack>#include <queue>#include <vector>#include <bitset>#include <functional>using namespace std;#define LL long longconst int INF = 0x3f3f3f3f;LL n;int a[10] = { 0,4,4,6,6,7,8,8,8 };int main(){ int t; scanf("%d", &t); while (t--) { scanf("%lld", &n); if (n <= 8) { printf("%d\n", a[n]); continue; } LL k = (LL)sqrt(1.0*n / 2); LL ans = k * 4, m = 2 * k*k; if (n == m) printf("%lld\n", ans); else if (n <= m + k - 1) printf("%lld\n", ans + 1); else if (n <= m + k * 2) printf("%lld\n", ans + 2); else if (n <= m + k * 3 - 1) printf("%lld\n", ans + 3); else printf("%lld\n", ans + 4); } return 0;}
阅读全文
0 0
- HDU6154-CaoHaha's staff
- hdu6154 CaoHaha's staff
- 【HDU6154】CaoHaha's staff (二分+规律)
- HDU6154 CaoHaha's staff 找规律|签到
- hdu6154-CaoHaha's staff(找规律)
- hdu6154 CaoHaha's staff 找规律
- hdu6154 CaoHaha's staff CCPC网赛1005 找规律+构造
- hdu6154-CCPC网络赛&规律-CaoHaha's staff
- HDU6154 CaoHaha's staff(规律,2017中国大学生程序设计竞赛
- 2017CCPC网络赛1005 hdu6154 CaoHaha's staff
- CaoHaha's staff
- HDU_6154 CaoHaha's staff
- CaoHaha's staff
- hdu-CaoHaha's staff
- HDU 6154 CaoHaha's staff
- CaoHaha's staff(hdoj6154)
- Hdu 6154 CaoHaha's staff
- HDU 6154 CaoHaha's staff
- C++函数返回值发生的对象复制
- 第一个.NetCore 2.0程序
- Java微信公众平台开发之将本地开发环境映射到公网访问
- gridControl
- flex-layout Responsive API
- HDU6154-CaoHaha's staff
- sysConfig.bat 闪退问题及此处不应有 \Java\jdk1.7.0_79问题的解决
- 使用python的BeautifulSoup库解析页面应选择适当容错能力的解析器
- openoffice问题:conversion failed: could not save output document; OOo errorCode: 283
- Android 三大图片缓存原理、特性对比
- 1159. 【NOI2002】银河英雄说(并查集)
- 接口自动化之thirdDay JsonGuolvTest 过滤掉某个字段的值 price
- 2017中国大学生程序设计竞赛
- Mapreduce二次排序实例