poj 1065 Wooden Sticks (greedy solved) 求最少启动时间。

贪心解决

题意:有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;
}
                        
                        
    


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值