贪心解决
题意:有n个木棒,分别不同的长度和不同的重量,一个机器需要处理这些木棒,如果第i+1个木棒的重量和长度都>=第i个处理的木棒,
那么将不会耗费时间,否则需要增加一个单位的时间,问最少需要多少时间处理完(包括机器启动的时间)
我感觉其他方法怎么也可以解决呢。没有试验!以后试。
// poj 1065 贪心解决~感觉其他方法也可以解决呢,以前好像做一个树状数组的方法,可以解决这个问题...~
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <algorithm>
using namespace std;
const int N = 5005;
struct node {
int x, y;
}t[N];
bool cmp(const node a, const node b) {
if(a.x == b.x) return a.y < b.y;
return a.x < b.x;
}
int vis[N];
int main() {
int T;
scanf("%d", &T);
while(T--) {
int n, i, j;
scanf("%d", &n);
for(i = 0; i < n; i++) {
scanf("%d%d", &t[i].x, &t[i].y);
}
sort(t, t+n, cmp);
memset(vis, 0, sizeof(vis));
int count = 0;
for(i = 0; i < n; i++) {
if(!vis[i]) {
int k = i;
for(j = i+1; j < n; j++) {
if(!vis[j]) {
if(t[j].y >= t[k].y) {
vis[j] = 1;
k = j;
}
}
}
vis[i] = 1;
count++;
}
}
printf("%d\n", count);
}
system("pause");
return 0;
}