Transmission Door
Thinking of solving problems
It is better to think, with a queue, and then put all the points together in order, in turn queued. Each time you check the type of the team head element is the current queue element type, yes, the words have been \ (pop\), each update answer can be.
Code
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include < Cmath> #include <queue>using namespace std;const int maxn = 1000005;inline Int rd () {int X=0;char ch=getchar (); while (!isdigit (CH)) Ch=getchar (); while (IsDigit (ch)) {x= (x<<1) + (x<<3) +ch-' 0 '; Ch=getchar ();} return x; }int n,k,ans=1e9,cnt,num;int vis[maxn];struct data{int col,t; friend BOOL operator< (const data a,const data B) {return a.t<b.t; }}data[maxn],tmp;queue<int> Q;int Main () {n=rd (); k=rd (); int x; for (int i=1;i<=k;i++) {x=rd (); tmp.col=i; while (x--) {tmp.t=rd ();d ata[++cnt]=tmp;} } sort (data+1,data+1+cnt); for (int i=1;i<=cnt;i++) {Q.push (i); if (!vis[data[i].col]) num++;vis[data[i].col]=i; while (Q.size ()) {X=q.front (); if (vis[data[x].col]!=x) Q.pop (); else break; } if (num==k) ans=min (ans,data[i].t-data[x].t); }cout<<ans; return 0;}
Luogu P2564 [SCOI2009] Birthday Gift (queue + simulation)