POJ
来源:互联网 发布:百度关键词排名软件 编辑:程序博客网 时间:2024/06/05 15:06
题意:
求给每个时间段的牛分配牛棚,时间不冲突的牛可以在一个牛棚。用优先队列和贪心。
Help FJ by determining:
- The minimum number of stalls required in the barn so that each cow can have her private milking period
- An assignment of cows to these stalls over time
Lines 2..N+1: Line i+1 describes cow i's milking interval with two space-separated integers.
Lines 2..N+1: Line i+1 describes the stall to which cow i will be assigned for her milking period.
51 102 43 65 84 7
412324
Here's a graphical schedule for this output:
Time 1 2 3 4 5 6 7 8 9 10Stall 1 c1>>>>>>>>>>>>>>>>>>>>>>>>>>>Stall 2 .. c2>>>>>> c4>>>>>>>>> .. ..Stall 3 .. .. c3>>>>>>>>> .. .. .. ..Stall 4 .. .. .. c5>>>>>>>>> .. .. ..Other outputs using the same number of stalls are possible.
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<queue>
#define maxn 60000
using namespace std;
typedef pair<int ,int>k;
struct node{
int s,t;
int d;
int pos,pos1;
}p[maxn];
bool cmp(node a,node b)
{
if(a.s==b.s)
return a.t<b.t;
return a.s<b.s;
}
bool operator < (constnode &a,constnode &b)
{
if(a.t==b.t)
return a.s>b.s;
return a.t>b.t;
}
int main()
{
int use[maxn];
memset(use,0,sizeof(use));
priority_queue<node>que;
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d%d",&p[i].s,&p[i].t);
p[i].pos=i;
p[i].d=p[i].t-p[i].s;
p[i].pos1=i;
}
sort(p,p+n,cmp);
int ans=1;
use[p[0].pos]=1;
que.push(p[0]);
for(int i=1;i<n;i++)
{
if(que.top().t<p[i].s&&!que.empty())
{
use[p[i].pos]=use[que.top().pos];
que.pop();
}
else
{
ans++;
use[p[i].pos]=ans;
}
que.push(p[i]);
}
// sort(p,p+n,cmp3);
printf("%d\n",ans);
for(int i=0;i<n;i++)
printf("%d\n",use[i]);
return 0;
}
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- poj
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- 机器学习:归纳偏好-“没有免费的午餐”定理
- 数据库不同层次的优化策略
- CISA国际注册信息系统审计师
- echarmap使用教程
- iOS视频 ZFPlayer使用
- POJ
- Oracle 27个常用例子
- sublime text3 快捷键
- 单元测试 在导入注解@test是报mistch 错误,无法导入原因
- Robotframework(1):配置基础环境
- 读取JPG文件作为caffe网络结构的输入
- 【Mybatis从0到1-014】查询缓存
- 剑指offer面试题16 反转链表
- Linux虚拟内存空间分布