POJ3190Stall Reservations

POJ3190Stall Reservations

Oh those picky N (1 <= N <= 50,000) cows! They are so picky that each one will only be milked over some precise time interval A..B (1 <= A <= B <= 1,000,000), which includes both times A and B. Obviously, FJ must create a reservation system to determine which stall each cow can be assigned for her milking time. Of course, no cow will share such a private moment with other cows. 

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

Many answers are correct for each test dataset; a program will grade your answer.

Input

Line 1: A single integer, N 

Lines 2..N+1: Line i+1 describes cow i's milking interval with two space-separated integers.

Output

Line 1: The minimum number of stalls the barn must have. 

Lines 2..N+1: Line i+1 describes the stall to which cow i will be assigned for her milking period.

Sample Input

5
1 10
2 4
3 6
5 8
4 7

Sample Output

4
1
2
3
2
4

大致意思:有 n头牛(1<=n<=50,000)要挤奶。给定每头牛挤奶的时间区间[A,B] (1<=A<=B<=1,000,000,A,B为整数)。
牛需要呆畜栏里才能挤奶。一个畜栏同一时间只能容纳一头牛。问至少需要多少个畜栏,才能完成全部挤奶工作,以及每头牛都
放哪个畜栏里(Special judged)
去同一个畜栏的两头牛,它们挤奶时间区间哪怕只在端点重合也是不可以的。

#include <iostream>
#include <queue> 
#include <algorithm>
using namespace std;
const int MAXC = 50000+10;
struct cow{
	int s,e,num;
	bool operator < (const cow &c) const{
		return s < c.s;
	}
}cows[MAXC]; 
struct stall{
	int num,e;
	bool operator < (const stall &s) const{
		return e > s.e;
	}
};
priority_queue<stall> p;
int solve[MAXC];
int main(){
	int n;
	cin >> n;
	for(int i = 0;i<n;i++){
		cows[i].num = i+1; 
		cin >> cows[i].s >> cows[i].e;
	}
	sort(cows,cows+n);
	stall early;
	//处理第一只牛 
	int cnt = 1;
	early.num = cnt;
	early.e = cows[0].e;
	p.push(early);
	solve[cows[0].num] = cnt;
	for(int i = 1;i<n;i++){
		early = p.top();
		p.pop();
		if(cows[i].s > early.e){
			solve[cows[i].num] = early.num;
			early.e = cows[i].e;
		}else{
			cnt++;
			solve[cows[i].num] = cnt;
			stall news;
			news.num = cnt;
			news.e = cows[i].e;
			p.push(news);
		}
		p.push(early);
	}
	
	cout << cnt << endl;
	for(int i = 1;i<=n;i++)
		cout << solve[i] << endl;
	
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
基于MySQL,设计实现一个简单的旅行预订系统。该系统涉及信息航班、大巴班车、宾馆房间和客户数据等信息。其关系模式如下: FLIGHTS (String flightNum, int price, int numSeats, int numAvail, String FromCity, String ArivCity); HOTELS(String location, int price, int numRooms, int numAvail); BUS(String location, int price, int numBus, int numAvail); CUSTOMERS(String custName,custID); RESERVATIONS(String custName, int resvType, String resvKey) 为简单起见,对所实现的应用系统作下列假设: 1. 在给定的一个班机上,所有的座位价格也一样;flightNum是表FLIGHTS的一个主码(primary key)。 2. 在同一个地方的所有的宾馆房间价格也一样;location是表HOTELS的一个主码。 3. 在同一个地方的所有大巴车价格一样;location是表 BUS的一个主码。 4. custName是表CUSTOMERS的一个主码。 5. 表RESERVATIONS包含着那些和客户预订航班、大巴车或宾馆房间相应的条目,具体的说,resvType指出预订的类型(1为预订航班,2为预订宾馆房间,3为预订大巴车),而resvKey是表RESERVATIONS的一个主码。 6. 在表FLIGHTS中,numAvail表示指定航班上的还可以被预订的座位数。对于一个给定的航班(flightNum),数据库一致性的条件之一是,表RESERVATIONS中所有预订航班的条目数加上该航班的剩余座位数必须等于该航班上总的座位数。这个条件对于表BUS和表HOTELS同样适用。 应用系统应完成如下基本功能: 1. 航班,大巴车,宾馆房间和客户基础数据的入库,更新(表中的属性也可以根据你的需要添加)。 2. 预定航班,大巴车,宾馆房间。 3. 查询航班,大巴车,宾馆房间,客户预订信息。 4. 查询某个客户的旅行线路。 5. 检查预定线路的完整性。 6. 其他任意你愿意加上的功能。 作业检查: 1. 提交源程序,可执行程序,以及程序运行说明。 2. 系统分析、设计实现报告。 3. 考试前检查完毕,延迟拒收。 4. 提交word文件,形式为:学号_姓名

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值