10588

这题wa 了 八次 你说 巨弱  orz 大神   总结一下  没有将所有的情况考虑清楚 ,当有的时候一个人已经全部看完的时候 别的人还没开始 但是我就把他给结束了 

#include <iostream>
#include<queue>
#include<cstdio>
using namespace std;
const int maxn=1100;
struct point{
   long long ti;
   int num;
   bool operator <(const point &a)const{
     return ti>a.ti||(ti==a.ti&&num>a.num);
    }
};
priority_queue<point> doc[maxn];
queue<int>pat[maxn];
int main()
{
     int t;
     point temp;
     scanf("%d",&t);
     while(t--){
         int n,m,d;
         long long first=0,after=0,cur,ans=0,T;
         scanf("%d%d",&n,&m);
         for(int i=1;i<=n;i++){
            int cas;
            cin>>temp.ti>>cas;
            temp.num=i;
            if(cas>0){
                    ++first; scanf("%d",&d);  doc[d].push(temp); cas--;
            }
            while(cas--){
                scanf("%d",&d);
                ++first;
                pat[i].push(d);
            }
         }
         cur=-1;
         T=-2;
         while(first!=after){

                if(T>cur) cur=T;
                else cur++;
                T=100000000;
                for(int i=1;i<=m;i++)
                if(!doc[i].empty()){
                    temp=doc[i].top();
                    if(temp.ti<=cur){
                        T=cur;
                        ++after;
                        ans=cur+1;
                        doc[i].pop();
                        if(!pat[temp.num].empty()){
                            d=pat[temp.num].front();
                            pat[temp.num].pop();
                            temp.ti=cur+1;
                            doc[d].push(temp);
                        }
                    }
                    else T=T>temp.ti?temp.ti:T;
                }
                if(first==after) break;

         }
    cout<<ans<<endl;
     }

    return 0;
}


 

原文地址:https://www.cnblogs.com/Opaser/p/3662041.html