hdu6154
来源:互联网 发布:宁波大学网络注销 编辑:程序博客网 时间:2024/06/10 15:38
CaoHaha's staff
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 98 Accepted Submission(s): 49
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
思路:先打表把边数为x的能包含的最多碎片正方形求出来(遇到边数为4的倍数的边数就直接为斜的正方形,公式出里面包含的碎片正方形个数,再通过这个来求其他三种情况,每次把两条斜的边改为竖直和水平)。
#include<iostream>#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;double d[1000005];void init(){for(int i=0;i<4;i++)d[i]=0;d[4]=2;d[5]=2.5;d[6]=4;d[7]=5.5;for(int i=8;i<1000000;i=i+4){d[i]=((double)i*i)/8;d[i+1]=d[i]+(double)(i-2)/4;d[i+2]=d[i+1]+(double)(i-2)/4+1;d[i+3]=d[i+2]+(double)(i-2)/4+1;}//for(int i=0;i<100;i++)cout<<d[i]<<endl;}int main(){int t;scanf("%d",&t);init();while(t--){int n;scanf("%d",&n);//printf("%lf\n",d[n]);printf("%d\n",lower_bound(d,d+100000,n)-d);}}
阅读全文
0 0
- hdu6154
- hdu6154 规律啊规律
- HDU6154-CaoHaha's staff
- hdu6154 CaoHaha's staff
- HDU6154(找规律)
- 【HDU6154 2017中国大学生程序设计竞赛
- HDU6154——找规律
- 【HDU6154】CaoHaha's staff (二分+规律)
- HDU6154 CaoHaha's staff 找规律|签到
- hdu6154-CaoHaha's staff(找规律)
- hdu6154 CaoHaha's staff 找规律
- 数学+二分 hdu6154 CCPC2017网络赛 1005
- hdu6154 CaoHaha's staff CCPC网赛1005 找规律+构造
- hdu6154-CCPC网络赛&规律-CaoHaha's staff
- HDU6154 CaoHaha's staff(规律,2017中国大学生程序设计竞赛
- 2017CCPC网络赛1005 hdu6154 CaoHaha's staff
- Java线程八锁
- Hibernate的count(*)函数通过调用uniqueResult方法的返回值类型
- noip2013day1
- Android中使用数据库保存数据
- Redis--persistence(持久化)
- hdu6154
- iOS 数据结构~链表简介
- 笔记:堆的增删改查(数组实现)
- SpringMVC 注解开发
- Linux部署web程序
- nodgd 好路线 noip 2015 模拟赛 T3
- 关于局域网内多人通过IP连接同一个sql数据库的问题
- 原码,反码,补码详解
- 辗转相除法求最大公约数