hdu 6154 CaoHaha's staff
来源:互联网 发布:mutlab定一个数组 编辑:程序博客网 时间:2024/06/05 00:42
CaoHaha's staff
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 491 Accepted Submission(s): 288
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
最长边往外拉出来变成一个梯形
#include<stdio.h>#include<string.h>using namespace std;long long a[1000003];void init(){ memset(a,0,sizeof(a)); a[4]=2; a[5]=2; a[6]=4; for(int i=7;i<=1000000;i++) { if(i%4==2) { long long x=i/4; long long y=x+1; a[i]=x*y*2; } else if(i%4==0) { long long x=i/4; a[i]=x*x*2; } else if(i%4==1) { long long x=i/4; a[i]=a[i-1]+(x-1); } else { long long y=i/4; a[i]=a[i-1]+(y); } }}int main(){ int T; init(); scanf("%d",&T); while(T--) { long long n; scanf("%lld",&n); if(n==0) { printf("0\n"); continue; } int r=4,l=1000000; int mid=0; for(int i=1;i<=40;i++) { mid=(r+l)/2; if(a[mid]>n) l=mid; else r=mid; } if(a[mid]<n) mid++; if(a[mid-1]>=n) mid--; printf("%d\n",mid); }}
阅读全文
0 0
- 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
- HDU 6154 CaoHaha's staff
- HDU 6154 CaoHaha's staff
- hdu-CaoHaha's staff
- HDU 6154 CaoHaha's staff 找规律
- HDU 6154-CaoHaha's staff(ccpc)
- 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【找规律】
- ubuntu 安装 emacs
- JUnit软件测试技术(工具)
- 二维码生成原理
- struts2_教程01
- Java多线程编程之Two-phase Termination模式
- hdu 6154 CaoHaha's staff
- 20个非常有用的java代码片段
- MyBatis调用存储过程
- redis入门,安装教程
- DOM节点【DOM】
- PHP之数据库设计
- 闲聊内存,我所知道的那些事
- 3.7 FreeeRTOS----不运行状态
- Oracle数据库