hdu 4476 Cut the rope
来源:互联网 发布:python 去除重复元素 编辑:程序博客网 时间:2024/05/22 07:02
Cut the rope
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 206 Accepted Submission(s): 99
Problem Description
Now we have some ropes. For each rope, you can cut it only once at any place, or you can also do nothing on it.
If we cut these ropes optimally, how many ropes we can get at most with the same length?
If we cut these ropes optimally, how many ropes we can get at most with the same length?
Input
There is an integer T (1 <= T <= 100) in the first line, indicates there are T test cases in total.
For each test case, the first integer N (1 <= N <= 100000) indicates there are N ropes. And then there are N integers whose value are all in [1, 100000], indicate the lengths of these ropes.
For each test case, the first integer N (1 <= N <= 100000) indicates there are N ropes. And then there are N integers whose value are all in [1, 100000], indicate the lengths of these ropes.
Output
For each test case, you should output one integer in one line, indicates that the number of ropes we can get at most with the same length if we cut these ropes optimally.
Sample Input
31 12 1 23 2 3 3
Sample Output
235HintFor Sample 1, we can get two ropes with 0.5 unit length. For Sample 2, we can get three ropes with 1 unit length. For Sample 3, we can get five ropes with 1.5 unit length.题意:n条绳子,每条绳子可以剪一次,也可以不剪,问最多能够得到多少条相同长度的绳子解题思路:能够想到的一种做法是,枚举每条绳子一半的长度,求最大值。但是n到100000,直接暴力枚举会超时。用s[i]表示小于等于i长的绳子数,如果当前枚举的绳子长度是a/2,则能够获取的最长相同长度绳子数为:总的绳子数n减去比a/2短的绳子数;还应加上a长的绳子数,因为a长的绳子是对半截取,所以会多出一倍,最后求得最大值。AC代码:#include <iostream>#include <cstring>#include <cstdio>#define N 100005using namespace std;int main(){ int t,a,n,f[N],s[N]; scanf("%d",&t); while(t--) { scanf("%d",&n); memset(f,0,sizeof(f)); for(int i=0;i<n;i++) { scanf("%d",&a); f[a]++; } s[0]=0; for(int i=1;i<N;i++) s[i]=s[i-1]+f[i]; int max=0,t; for(int i=1;i<N;i++) { if(f[i]>0) { t=n-s[(i-1)/2]+f[i]; if(t>max) max=t; } } printf("%d\n",max); }return 0;}
- hdu 4476 Cut the rope
- hdu 4476 Cut the rope
- HDU 4476 Cut the rope
- hdu 4476 Cut the rope
- HDU-4476 Cut the rope (枚举、前缀和)
- cocos2d cut the rope
- NYOJ Cut the rope
- Cut The Rope正式登录pc
- hdu 4344 Mark the Rope
- hdu 4344 Mark the Rope
- HDU 4344 Mark the Rope
- html5在线网页游戏-Cut The Rope割绳子免费版
- cut the rope HTML 5版本背后的开发故事
- 《Cut The Rope》 HTML 5版背后的开发故事
- hdu - 4344 - Mark the Rope - 大数分解
- 用 Box2D 来制作类似 Cut the Rope 游戏里的绳子
- NYOJ 651 Cut the rope(DP, 经典的整数划分问题)
- 带你一起分析cut the rope(切绳子游戏)中绳子的制作方法
- [深入浅出Cocoa]iOS网络编程之CFNetwork
- C++构造函数虚拟化
- Maven学习(八)- 构建MyBatis项目
- c#从配置文件读取多张网卡ip
- 彻底killed掉某用户进程
- hdu 4476 Cut the rope
- 《有关搜索题目》
- 求简单链表长度!
- Java 强引用、 软引用、 弱引用、虚引用
- 函数回调方法
- 微生物增值--蓝桥杯
- PHP 持久层的简单实现
- 2013 编程之美 初赛第二场 管道系统小数据
- 第四次上机实验任务