poj3190
来源:互联网 发布:淘宝偷图技巧 编辑:程序博客网 时间:2024/05/29 16:21
题目链接:http://poj.org/problem?id=3190
题意:一批奶牛要挤奶,挤奶的时候要呆在一个棚子里,并且一个棚子只能给一个奶牛。
解题思路:这道题目我一开始就想错了,导致了我WA了好多次,后来参照了http://blog.csdn.net/z309241990/article/details/19566625#comments这篇博客才写了出来
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<queue>using namespace std;const int maxn=60000;int n,use[maxn];struct Node{ int l; int r; int pos; bool operator <(const Node &a)const {if(r==a.r) return l>a.l;return r>a.r; }}a[maxn];priority_queue<Node> q;bool cmp(Node a,Node b){ if(a.l==b.l)return a.r<b.r; return a.l<b.l;}int main(){ while(scanf("%d",&n)!=EOF) {for(int i=0;i<n;i++){ scanf("%d%d",&a[i].l,&a[i].r); a[i].pos=i;}sort(a,a+n,cmp);q.push(a[0]);int now=0,ans=1;use[a[0].pos]=1;for(int i=1;i<n;i++){ if(!q.empty()&&q.top().r<a[i].l) {use[a[i].pos]=use[q.top().pos];q.pop(); } else {ans++;use[a[i].pos]=ans; } q.push(a[i]);}printf("%d\n",ans);for(int i=0;i<n;i++) printf("%d\n",use[i]);while(!q.empty()) q.pop(); } return 0;}
0 0
- poj3190
- poj3190
- POJ3190
- poj3190
- POJ3190
- poj3190
- poj3190 贪心
- POJ3190 Stall Reservations 贪心
- poj3190 (mulitset贪心)
- POJ3190 Stall Reservations 【贪心】
- poj3190 区间贪心 + STL
- Stall Reservations - POJ3190 贪心
- POJ3190-Stall Reservations
- poj3190 poj2393 贪心
- poj3190(区间贪心)
- POJ3190 Stall Reservations
- 贪心(好题)--poj3190
- poj3190(贪心,优先队列)
- python3 导入模块
- JS快捷键
- PRML Charpter 2 Probability Distribution 2.3.5 Sequential estimation讲义摘要
- 解决:AMQ应用部署到weblogic服务器上出现“找不到匹配的方法setLifo"
- CUDA: 使用shared memory
- poj3190
- 【蓝桥杯训练】------2n皇后问题
- 有没有办法获取最近操作的联系人
- Ubuntu 14.04 安装 Intel MKL + OpenCV
- 【spoj375】Query on a tree【树链剖分】【或者动态树,那样常数就完了T_T】
- C++省略号类型和参数个数不确定函数参数范例
- VC++动态链接库(DLL)编程深入浅出(zz)
- 反距离权重法生成DEM(利用KD-tree实现KNN算法)
- C#实现队列的基本操作