HDU CCPC 1005 CaoHaha's staff
来源:互联网 发布:淘宝店铺网名昵称大全 编辑:程序博客网 时间:2024/06/04 23:32
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(大神们不要喷我,我只是一只菜鸟)题解:题意为N*N 并且单位长度为1的格子,每次可以连接邻边或者对角线,T组测试数据,问围成n面积最少需要多少条边!!纯粹的一道找规律的题,我们每加一条边 都尽可能的将图形拼成正方形(以对角线为边的正方形最大)我们可以很容易的求得面积为偶数的最小边数,可以通过减少一条边推出当前的矩形较长边的关系。。。话不多说 直接上代码
#include<iostream>using namespace std;int T,n;unsigned long long ans=0;int main(){ ios::sync_with_stdio(false); int a[9]={0,4,4,6,6,7,8,8,8}; cin>>T; while(T--) { ans=0; cin>>n; if(n<=4) cout<<a[n]<<endl; else { int num=0; n-=4; int cnt=8; while(n>=cnt) { n-=cnt; num+=4; cnt+=4; } int k=1; k+=num/4; num++; if(n>k) num++; if(n>(2*k+2)) num++; if(n>(3*k+2)) num++; ans=num+a[4]; cout<<ans<<endl; } } return 0;}
阅读全文
1 0
- HDU CCPC 1005 CaoHaha's staff
- HDU 6154-CaoHaha's staff(ccpc)
- 2017ccpc网赛-1005-CaoHaha's staff
- ccpc预选赛-1005CaoHaha's staff
- hdu-CaoHaha's staff
- 2017CCPC 网络选拔赛 1005 CaoHaha's staff
- hdu6154 CaoHaha's staff CCPC网赛1005 找规律+构造
- 2017ccpc网络选拔赛 1005 CaoHaha's staff
- 2017CCPC网络赛1005 hdu6154 CaoHaha's staff
- 2017 ccpc网络预选赛 CaoHaha's staff
- 2017ccpc网络赛CaoHaha's staff
- HDU 6154 CaoHaha's staff
- Hdu 6154 CaoHaha's staff
- HDU 6154 CaoHaha's staff
- HDU 6154 CaoHaha's staff
- HDU 6154 CaoHaha's staff
- hdu 6154 CaoHaha's staff
- hdu 6154 CaoHaha's staff
- MOOC清华《面向对象程序设计》第3章编程题第1题:重载函数运算符以封装排序算法
- ES6之-字符串的新特性
- HDU
- 人生苦短,少打游戏
- 分支结构(switch)
- HDU CCPC 1005 CaoHaha's staff
- 跨域资源共享 CORS 详解
- //将一个ANSI编码格式纯文本文件以UTF-8的形式读到另一个文件中去
- MySQL初学学习的一点细节上小经验记载
- nyoj 开心的小明 动态规划 01背包
- Luogu P1282 多米诺骨牌
- 设计模式之单例模式
- 关注民生民情
- [LintCode]97.二叉树的最大深度