• 心急的C小加


    心急的C小加

    时间限制:1000 ms  |  内存限制:65535 KB
    难度:4
     
    描述

    C小加有一些木棒,它们的长度和质量都已经知道,需要一个机器处理这些木棒,机器开启的时候需要耗费一个单位的时间,如果第i+1个木棒的重量和长度都大于等于第i个处理的木棒,那么将不会耗费时间,否则需要消耗一个单位的时间。因为急着去约会,C小加想在最短的时间内把木棒处理完,你能告诉他应该怎样做吗?

     
    输入
    第一行是一个整数T(1<T<1500),表示输入数据一共有T组。
    每组测试数据的第一行是一个整数N(1<=N<=5000),表示有N个木棒。接下来的一行分别输入N个木棒的L,W(0 < L ,W <= 10000),用一个空格隔开,分别表示木棒的长度和质量。
    输出
    处理这些木棒的最短时间。
    样例输入
    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 
    
    样例输出
    2
    1
    3
     
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    struct node{
        int l, w;
        bool operator < (const node &a)const{
            if(l == a.l)
                return w < a.w;
            return l < a.l;
        }
    }a[5005];
    int dp[5005];
    bool vis[5005];
    int main(){
        int T;
        scanf("%d", &T);
        while(T--){
            int n;
            scanf("%d", &n);
            for(int i = 0; i < n; i++){
                scanf("%d%d", &a[i].l, &a[i].w);
                vis[i] = 0;
            }
            sort(a, a+n);
            int ans = 0;
            for(int i = 0; i < n; i++){
                if(!vis[i]){
                    ans++;
                    node tmp;
                    tmp.l = a[i].l;
                    tmp.w = a[i].w;
                    for(int j = i+1; j < n; j++){
                        if(!vis[j] && tmp.l <= a[j].l && tmp.w <= a[j].w){
                            tmp.l = a[j].l;
                            tmp.w = a[j].w;
                            vis[j] = 1;
                        }
                    }
                }
            }
            printf("%d
    ", ans);
        }
        return 0;
    }
            
  • 相关阅读:
    BZOJ 4247 挂饰
    BZOJ 4247 挂饰
    BZOJ 1087(SCOI 2005) 互不侵犯
    BZOJ 1087(SCOI 2005) 互不侵犯
    bzoj 2093 [Poi2010]Frog——滑动窗口
    bzoj 2096 [POI2004]ZAW——二进制枚举
    bzoj 2276 [Poi2011]Temperature——单调队列
    CF 293E Close Vertices——点分治
    洛谷 4178 Tree——点分治
    洛谷 2634 [国家集训队]聪聪可可——点分治
  • 原文地址:https://www.cnblogs.com/ACMessi/p/4909961.html
Copyright © 2020-2023  润新知