ccpc预选赛-1005CaoHaha's staff
来源:互联网 发布:php reflection的作用 编辑:程序博客网 时间:2024/05/29 18:46
CaoHaha's staff
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2089 Accepted Submission(s): 818
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
找规律推出公式。
首先我们要在相同时间找出我们能画出面积最大的图形。所以在边长相同的情况下面积越接近正方形面积越大,边数相同的时候边长越长越大所以边长尽量用根号2。
当边为1或2的时候不能形成封闭图像。边为三时只有一种解法边长为1,1,根号2的三角形,面积为1/2,向下取整为0.。设边有n条。
当n为偶数时,组成一个边长尽量相近的矩形。
比如边长为16.
4*4=16;3*5=15;2*6=12;1*7=7;
所以公式为
n/4*(n/4+(n%4)/2)*2;
奇数条边的时候最优情况是这样的
所以公式为
(n-1)/4*((n-1)/4+((n-1)%4)/2)*2+((n-1)/4+((n-1)%4)/2-0.5;
所以代码为:
#include<cstdio>#include<cstring>#include<cmath>#include<iostream>#include<algorithm>#include<queue>using namespace std;double a[500010];int main(){ a[0]=0;a[1]=0;a[2]=0;a[3]=0; for(int i=4;i<=100000;i++){ if(i%2==0){ int k=i%4; k=k/2; a[i]=(int)2*(i/4)*(i/4+k); } else{ int k=(i-1)%4; k=k/2; a[i]=(int)a[i-1]+(int)((i-1)/4+k-0.5); } } int t; scanf("%d",&t); while(t--){ long long n,x; scanf("%lld",&n); x=lower_bound(a,a+100000,n)-a; printf("%lld\n",x); }}
阅读全文
0 0
- ccpc预选赛-1005CaoHaha's staff
- 2017 ccpc网络预选赛 CaoHaha's staff
- HDU CCPC 1005 CaoHaha's staff
- 2017ccpc网赛-1005-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
- HDU 6154-CaoHaha's staff(ccpc)
- 2017ccpc网络赛CaoHaha's staff
- 2017CCPC网络选拔赛1005CaoHaha's staff(规律贪心)
- hdu6154-CCPC网络赛&规律-CaoHaha's staff
- 2017ccpc网络赛——CaoHaha's staff
- 1005 ——CaoHaha's staff
- CaoHaha's staff
- HDU_6154 CaoHaha's staff
- CaoHaha's staff
- HDU6154-CaoHaha's staff
- Mysql5.6升级到5.7步骤详解
- mac本地搭建伪分布式Hadoop和HBase遇到的问题
- java 正则去除中文标点符号
- LeetCode 26: Remove Duplicates from Sorted Array
- HDU2063--过山车(二分匹配,二分图)
- ccpc预选赛-1005CaoHaha's staff
- typedef 和 define 的用法
- 线程同步的三种方法(Java 并发编程 concurrent包复习)
- Asp.Net core上传文件代码
- GIT和SVN比较
- Android中的子线程和服务的使用
- 线段树(一)
- VS2013下glew库链接失败问题OpenGL.obj : error LINK2001: 无法解析的外部符号 __imp____glewFramebufferTexture2DEXT
- [leedcode]-- 27. Remove Element