刷题——Stall Reservations POJ
来源:互联网 发布:鬼魂探测器软件 编辑:程序博客网 时间:2024/06/12 08:08
/*
有n头牛,每头牛都有自己挤奶的时间,挤奶的时候每头牛都要单独挤奶
挤奶需要工具,问最少需要多少工具,同时输出每头牛使用的是哪件工具
每头牛先按开始时间排序,用两个数组,记录下不同机器最后使用的时间和每头牛使用的是哪头工具
遍历一遍,恰好在给定时间内通过,可以用优先队列优化一下,应该会快很多
*/
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
struct node{
int from,to,id;
};
node e[50005];
int out[50005];
int sy[50005];
bool cmp(node a,node b){
return a.from<b.from;
}
int n,num;
void f(int x){
for(int i=0;i<num;i++){
if(e[x].from>sy[i]){
sy[i]=e[x].to;
out[e[x].id]=i+1;
return;
}
}
sy[num++]=e[x].to;
out[e[x].id]=num;
}
void solve(){
sy[num++]=e[0].to;
out[e[0].id]=num;
for(int i=1;i<n;i++){
f(i);
}
}
void print(){
printf("%d\n",num);
for(int i=0;i<n;i++){
printf("%d\n",out[i]);
}
}
int main(){
while(~scanf("%d",&n)){
for(int i=0;i<n;i++){
scanf("%d %d",&e[i].from,&e[i].to);
e[i].id=i;
}
memset(out,0,sizeof(out));
memset(sy,0,sizeof(sy));
num=0;
sort(e,e+n,cmp);
solve();
print();
}
return 0;
}
有n头牛,每头牛都有自己挤奶的时间,挤奶的时候每头牛都要单独挤奶
挤奶需要工具,问最少需要多少工具,同时输出每头牛使用的是哪件工具
每头牛先按开始时间排序,用两个数组,记录下不同机器最后使用的时间和每头牛使用的是哪头工具
遍历一遍,恰好在给定时间内通过,可以用优先队列优化一下,应该会快很多
*/
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
struct node{
int from,to,id;
};
node e[50005];
int out[50005];
int sy[50005];
bool cmp(node a,node b){
return a.from<b.from;
}
int n,num;
void f(int x){
for(int i=0;i<num;i++){
if(e[x].from>sy[i]){
sy[i]=e[x].to;
out[e[x].id]=i+1;
return;
}
}
sy[num++]=e[x].to;
out[e[x].id]=num;
}
void solve(){
sy[num++]=e[0].to;
out[e[0].id]=num;
for(int i=1;i<n;i++){
f(i);
}
}
void print(){
printf("%d\n",num);
for(int i=0;i<n;i++){
printf("%d\n",out[i]);
}
}
int main(){
while(~scanf("%d",&n)){
for(int i=0;i<n;i++){
scanf("%d %d",&e[i].from,&e[i].to);
e[i].id=i;
}
memset(out,0,sizeof(out));
memset(sy,0,sizeof(sy));
num=0;
sort(e,e+n,cmp);
solve();
print();
}
return 0;
}
阅读全文
0 0
- 刷题——Stall Reservations POJ
- 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
- Stall Reservations POJ
- POJ 3190 Stall Reservations
- poj 3190 Stall Reservations
- 51单片机中使用ucos ii的优缺点
- NYOJ 59-小明组织活动的任务(置换)
- 模态框总结
- poj 1330 Nearest Common Ancestors(lca st)
- HDU 6097 Mindis(计算几何)
- 刷题——Stall Reservations POJ
- JavaWeb-ssm框架搭建
- js打开本地exe程序
- power designer远程连接oracle数据库并导出E-R图
- C语言中restrict的作用
- 《Drools7.0.0.Final规则引擎教程》番外实例篇——默认条件的陷阱
- javaSE和JavaEE的区别?
- DAY58JavaScript DOM大纲
- 以Postgre SQL冷备为主线实现Portal for ArcGIS 10.5至10.5.1的迁移