hdu4476


Cut the rope

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 13    Accepted Submission(s): 12


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?
 

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.
 

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
      
3 1 1 2 1 2 3 2 3 3
 

Sample Output
      
2 3 5
Hint
  For 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.
 

Source
 

Recommend
liuyiding
 


这场被坑爆了,杭电已经把题目挂了,我就把这题写了

其实不太难,任何一个长l的绳子分两段的话相当于让前面所有的长度小于l的加一个,而l/2的长度加2个,同时,因为l是整形小数部分可以统一认为是0.5方便理解和统计

#include <algorithm>
#include <stdio.h>
#include <cstring>
using namespace std;

int a[200020],b[200020];
int max(int a,int b)
{
    if (a>b) return a;
    else return b;
}
int main()
{
    int t,n,i,j,l,k,maxx;
    scanf("%d",&t);
    while (t--)
    {
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        scanf("%d",&n);
        k=0;
        maxx=0;
        for (i=0;i<n;i++)
        {
            scanf("%d",&l);
            l*=2;
            //for (j=1;j<=l;j++)
            a[l]++;
            b[l/2]++;
            k=max(k,l);
        }
        maxx=a[k];
        for (i=k-1;i>=1;i--)
        {
            //cout<<a[i]<<endl;
            a[i]=a[i+1]+a[i];
            maxx=max(a[i]+b[i],maxx);
        }
        printf("%d\n",maxx);
    }
}

这题比赛的时候用cin和cout结果超时了,我晕死。。。害我检查了2小时。。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值