3 条题解
-
2
~包过~111
#include<iostream> #include<algorithm> #include<cstring> #include<cmath> #include<queue> #include<vector> using namespace std; int n; typedef pair<int,int> PII; pair<PII,int> cows[50010];//记录每头牛吃草的时间段,奶牛编号 int id[50010];//记录每头牛的栅栏号; int main(){ cin>>n; for(int i=0;i<n;i++){ cin>>cows[i].first.first>>cows[i].first.second; cows[i].second=i; } sort(cows,cows+n); priority_queue<PII,vector<PII>,greater<PII> > qu; for(int i=0;i<n;i++){ if(qu.empty()||cows[i].first.first<=qu.top().first){ id[cows[i].second]=qu.size()+1; PII a1; a1.first=cows[i].first.second; a1.second=qu.size()+1; qu.push(a1); } else{ PII a=qu.top(); qu.pop(); PII b; b.first=cows[i].first.second; b.second=a.second; id[cows[i].second]=a.second; qu.push(b); } } cout<<qu.size()<<endl; for(int i=0;i<n;i++){ cout<<id[i]<<endl; } return 0; }
信息
- ID
- 23
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 2
- 标签
- 递交数
- 163
- 已通过
- 98
- 上传者