UVALive - 2326 Moving Tables

来源:互联网 发布:flash编程教程 编辑:程序博客网 时间:2024/05/20 17:25

题意:求最少的时间将桌子搬完,每次需要十分钟,但如果两次的区间步冲突的话,那么这两次是可以同时进行的,首先我们先排序,将尽量靠左边的排在前面,我们每次都先将最小的装进去,然后判断之后是否有可以继续装进去的区间,直到所有的判断完毕

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int MAXN =205;struct Node{    int l;    int r;    friend bool operator <(const Node &a,const Node &b){        if (a.l != b.l)            return a.l < b.l;        return a.r < b.r;    }}arr[MAXN];int vis[MAXN];int main(){    int t,n;    scanf("%d",&t);    while (t--){        memset(vis,0,sizeof(vis));        scanf("%d",&n);        for (int i = 0; i < n; i++){            int a,b,t;            scanf("%d%d",&a,&b);            if (a > b){                t = a;                a = b;                 b = t;            }            arr[i].l = (a + 1) / 2;            arr[i].r = (b + 1) / 2;        }        sort(arr,arr+n);        int cur = 0,ans = 0;        while (cur < n){            ans++;            int end = 0;            for (int i = 0; i < n; i++){                if (vis[i])                    continue;                if (arr[i].l > end){                    end = arr[i].r;                    cur++;                    vis[i] = 1;                }            }        }        printf("%d\n",ans*10);    }    return 0;}