POJ 3190 Stall Reservations
来源:互联网 发布:macd指标源码 编辑:程序博客网 时间:2024/05/17 04:10
题意:
说几头牛,每头牛挤牛奶的时间是分别是Ai到Bi,一个机器不能在相同的时间给超过一个牛挤牛奶,问最少用几个机器,和每个牛奶所用的机器编号。
思路:
首先,用每头牛开始的时间Ai进行一个排序,然后再用优先队列将最小的Bi为优先,如果最小Bi都比这个Ax大,则会重合,增加一个机器,否则用同一个机器。
代码:
#include<stdio.h>#include<queue>#include<algorithm>using namespace std;struct Node{ int A,B; int pre; bool operator <(const Node &c)const { if(B==c.B) return A>c.A; return B>c.B; }}x[50010];priority_queue<struct Node >q;int cmp(Node a,Node b){ return a.A<b.A;}int main(){ int N,d[50010]; scanf("%d",&N); for(int i=0;i<N;i++) { x[i].pre=i; scanf("%d %d",&x[i].A,&x[i].B); } sort(x,x+N,cmp); d[x[0].pre]=1; q.push(x[0]); int ans=1; for(int i=1;i<N;i++) { if(q.top().B<x[i].A) { d[x[i].pre]=d[q.top().pre]; q.pop(); } else { ans++; d[x[i].pre]=ans; } q.push(x[i]); } printf("%d\n",ans); for(int i=0;i<N;i++) printf("%d\n",d[i]); return 0;}
0 0
- poj 3190 Stall Reservations
- POJ-3190-Stall Reservations
- POJ-3190-Stall Reservations
- POJ 3190 Stall Reservations
- POJ-3190-Stall Reservations
- poj 3190Stall Reservations
- poj 3190 Stall Reservations
- poj 3190 Stall Reservations
- POJ 3190 Stall Reservations
- POJ 3190 Stall Reservations
- poj 3190 Stall Reservations
- POJ 3190 Stall Reservations
- poj 3190 Stall Reservations
- POJ 3190 Stall Reservations
- POJ 3190 Stall Reservations
- poj 3190 Stall Reservations
- poj 3190 Stall Reservations
- POJ 3190 Stall Reservations
- .NET的装箱与拆箱内幕
- java web进阶篇(七) JSP标准标签库 ** XML标签库 重点、函数标签库**
- xcode6 格式化代码
- CS0016: 未能写入输出文件“c:\WINDOWS\Microsoft.NET\Framework\.。。”--“拒绝访问
- hibernate学习第一天笔记
- POJ 3190 Stall Reservations
- Android应用开发——跑马灯效果
- Andriod双击退出
- ActionBar 显示选项菜单
- struts2前台页面控制时间格式
- 【随笔】记录解决无法进入Android Developers 及 SDK Manager无法更新问题的办法
- 泛型Java
- 图形报表,HighCharts
- java之旅