2017CCPC网络选拔赛1005CaoHaha's staff(规律贪心)
来源:互联网 发布:python thinter视频 编辑:程序博客网 时间:2024/06/05 02:25
2017CCPC网络资格赛1005
描述
“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.输入
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)样例输入
512345
样例输出
44667
题意:
意思是在坐标系中,输入给我们一个面积s1,我们需要围出一个面积s2,(s2>=s1)。
如何围出面积,有一定的约束方法。此坐标系平面由无数个单位面积为1的正方形组成,我们每一次可以沿着这个单位的边画一条线,或者是在沿着单位的对角线画一条线。
现在要求最少需要画几次。
思路
其实这个题好像有什么皮克定理,但是不会用。我就按照我的思路讲一下。
首先我们转变一下思路,我们要求得某面积的画的最少的次数,可以转变为某些次数可以得到的最大的面积。那么我们从4条边一直画,最多画到10条的时候,我们可以发现。当画的次数为4,6,8,10,12的时候,面积是
1*1*2,2*1*2,2*2*2,3*2*2,3*3*2
,也就是说有数m,n就是我们画的面积的长和宽(对于偶数面积来说,一定是一个矩形)。也就是说对于偶数面积,它所需要的最小次数的增长是有一定规律的,总结为,当m==n时,面积为(++m)*n
;当m!=n
时,面积为m*(++n)
.那画的次数为奇数所能得到的最大面积怎么确定呢?我们可以发现当画的次数为4的时候,长和宽都是1个单位(对角线和沿着边画都算一个单位),那么从4拓展到5,也就是1次画的次数拓展为2次,面积增加0.5;当画的次数为6的时候,长和宽分别是2个和1个单位,那么就是从max(2,1)扩展为1次,也就是2次扩展为3次,面积增加1.5.好了规律出来了,从偶数到奇数的变换,就是偶数的面积加上能够拓展出来的面积,拓展出来的面积又与max(长,宽)有关。
然后打表,读入面积后,就可以二分查找即可。
AC代码
#include<bits/stdc++.h> using namespace std; const int maxn = 1e6+5; double area[maxn]; int main() { area[4] = 2; int m = 2,n = 1; double temp; for(int i = 5;i<=maxn;i++) { if(i%2 != 0) { temp = (double)((i+1)/4 - 0.5); area[i] = area[i-1] + temp; } else { area[i] = m*n*2; if(m == n) m++; else n++; } } // cout<<area[maxn]; int T; scanf("%d",&T); while(T--) { double s; cin>>s; long long ans = lower_bound(area,area+99999,s) - area; printf("%d\n",ans); } return 0; }
- 2017CCPC网络选拔赛1005CaoHaha's staff(规律贪心)
- 2017CCPC 网络选拔赛 1005 CaoHaha's staff
- 2017ccpc网络选拔赛 1005 CaoHaha's staff
- 2017 ccpc网络预选赛 CaoHaha's staff
- 2017ccpc网络赛CaoHaha's staff
- 2017CCPC网络赛1005 hdu6154 CaoHaha's staff
- hdu6154-CCPC网络赛&规律-CaoHaha's staff
- 2017ccpc网赛-1005-CaoHaha's staff
- hdu6154 CaoHaha's staff CCPC网赛1005 找规律+构造
- CaoHaha's staff(中国大学生程序选拔赛2017年网络大赛)
- 2017ccpc网络赛——CaoHaha's staff
- HDU-2017中国大学生程序设计竞赛-网络选拔赛-1005-CaoHaha's staff
- 2017中国大学生程序设计竞赛(网络选拔赛) HDU 6154 CaoHaha's staff
- HDU CCPC 1005 CaoHaha's staff
- ccpc预选赛-1005CaoHaha's staff
- HDU 6154-CaoHaha's staff(ccpc)
- CCPC网赛 CaoHaha's staff(找规律+模拟扩展正方形)
- HDU 6154 CaoHaha's staff(规律)
- Atitit it 互联网 软件牛人的博客列表
- Cookie/Session详解
- 用word发CSDN blog,免去插图片的烦恼
- 转发和重定向的比较
- if的[]和[[]]
- 2017CCPC网络选拔赛1005CaoHaha's staff(规律贪心)
- Codeforces Round #424 E. Cards Sorting
- web运用程序在web容器加载顺序
- 基于redis的延迟消息队列设计
- C++求矩阵最小路径和进阶方法空间复杂度O(min {row, col})
- JVM(1):Java 类的加载机制
- A Secret 2017 CCPC 网络选拔赛 hdu 6153
- 日常培训一些记录
- C设计模式