Luogu P2564 [SCOI2009] Birthday Gift (queue + simulation)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.