|
|
Cut the ropeTime 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
Sample Output
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小时。。。
137

被折叠的 条评论
为什么被折叠?



