B. 心急的C小加
Time Limit: 1000ms
Memory Limit: 128000KB
64-bit integer IO format: Java class name:
Submit
Status
C小加有一些木棒,它们的长度和质量都已经知道,需要一个机器处理这些木棒,机器开启的时候需要耗费一个单位的时间,如果第i+1个木棒的重量和长度都大于等于第i个处理的木棒,那么将不会耗费时间,否则需要消耗一个单位的时间。因为急着去约会,C小加想在最短的时间内把木棒处理完,你能告诉他应该怎样做吗?
Input
第一行是一个整数T(1<T<1500),表示输入数据一共有T组。
每组测试数据的第一行是一个整数N(1<=N<=5000),表示有N个木棒。接下来的一行分别输入N个木棒的L,W(0 < L ,W <= 10000),用一个空格隔开,分别表示木棒的长度和质量。
Output
处理这些木棒的最短时间。
Sample Input
3
5
4 9 5 2 2 1 3 5 1 4
3
2 2 1 1 2 2
3
1 3 2 2 3 1
Sample Output
2
1
3
#include<stdio.h>
#include<algorithm>
using namespace std;
struct gg
{
int x,y;
} a[5500];
bool cmp(struct gg a,struct gg b)
{
if(a.x==b.x)
return a.y<b.y;
else
return a.x<b.x;
}
int b[5000];
int main()
{
int n;
scanf("%d",&n);
while(n--)
{
int t;
scanf("%d",&t);
int i,j,h=1;
for(i=0; i<t; i++)
{
scanf("%d%d",&a[i].x,&a[i].y);
}
sort(a,a+t,cmp);
b[0]=a[0].y;
for(i=1; i<t; i++)
{
for(j=0; j<h; j++)//b[0]一定最大
{
if(a[i].y>=b[j])
{
b[j]=a[i].y;
break;
}
}
if(j==h)
{
b[h]=a[i].y;
h++;
}
}
printf("%d\n",h);
}
return 0;
}
转载请注明原文地址: https://ju.6miu.com/read-677561.html