• poj 2376


    http://acm.pku.edu.cn/JudgeOnline/problem?id=2376

    在T天里干完一件事,有多只牛,每只牛负责连续几天,日期可能重叠。找出最少数量的牛干完这件事。(可能讲的不清楚)

     

    #include<stdio.h> 
    #include<algorithm> 
    using namespace std; 
    struct ORDER 
    { 
        int left; 
        int right; 
    }order[25001]; 
    
    bool cmp(ORDER a, ORDER b) 
    { 
        return a.left < b.left; 
    } 
    
    int main() 
    { 
        int n_cow, time, i, step, find, tot, ok, temp_right; 
        while(scanf("%d%d", &n_cow, &time)!=EOF) 
        { 
            for(i=0; i<n_cow; i++) 
                scanf("%d%d", &order[i].left, &order[i].right); 
            sort(order, order + n_cow, cmp); 
    
            if(order[0].left >1) 
            { 
                printf("-1\n"); 
                continue; 
            } 
             
            step = 0; 
            i = 0; 
            ok = 1; 
            tot = 0; 
    
            while(step < time && i < n_cow) 
            { 
                find = 0; 
                temp_right = 0; 
                while(order[i].left <= step + 1 && i < n_cow ) 
                { 
                    find = 1; 
                    if(order[i].right > temp_right) 
                        temp_right = order[i].right; 
                    i++; 
                } 
                if(!find) 
                { 
                    ok = 0; 
                    break; 
                } 
                step = temp_right; 
                tot++; 
            } 
            if(!ok || step < time) 
                printf("-1\n"); 
            else 
                printf("%d\n", tot); 
        } 
        return 0; 
    }  
    

  • 相关阅读:
    Swift之 ? 和 !
    objective-c工程使用swift
    NSMethodSignature和NSInvocation的用法
    NSTimer
    iOS 的 XMPPFramework
    计算string高度
    python学习:猜数字小游戏
    python 各种控制语句
    ③ 小程序的代码组成
    ③ 组件&props
  • 原文地址:https://www.cnblogs.com/submarinex/p/1941256.html
Copyright © 2020-2023  润新知