Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
纪念一下#include<iostream> #include<algorithm> #include<queue> #include<vector> using namespace std; const int maxn=1e6+7; struct cow{ int l,r; int num; int stalk; }; class cmp1{ public: bool operator()(cow x,cow y) { return x.l>y.l; } }; class cmp2{ public: bool operator()(cow x,cow y) { return x.r>y.r; } }; int main() { int n;scanf("%d",&n);cow tmp; priority_queue<cow,vector<cow>,cmp2> q2; priority_queue<cow,vector<cow>,cmp1> q1; vector<int> cctime; vector<cow> mycow(n+1);vector<int> number(n+1); for(int i=1;i<=n;i++)scanf("%d%d",&mycow[i].l,&mycow[i].r),cctime.push_back(mycow[i].l),cctime.push_back(mycow[i].r+1),mycow[i].num=i,q1.push(mycow[i]); sort(cctime.begin(),cctime.end()); cctime.erase(unique(cctime.begin(),cctime.end()),cctime.end()); int cnt=0; queue<int> stall; int maxv=0; for(int j=0;j<cctime.size();j++) { int i=cctime[j]; while(!q2.empty()&&i>q2.top().r) { stall.push(q2.top().stalk); // cout<<i<<"*****stall**"<<q2.top().stalk<<"******"<<q2.top().l<<"***outout**"<<q2.top().r<<endl; number[q2.top().num]=q2.top().stalk; q2.pop(); } while(!q1.empty()&&i>=q1.top().l) { if(stall.empty())++cnt,stall.push(cnt); cow tmp=q1.top();tmp.stalk=stall.front(); // cout<<i<<"************intint******stall****"<<tmp.stalk<<"****************"<<tmp.l<<" "<<tmp.r<<endl; q2.push(tmp);q1.pop();stall.pop(); } } cout<<cnt<<endl; for(int i=1;i<=n;i++)cout<<number[i]<<endl; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator