1046 - Workshops

The first Californian Conference on Holism took place back in 1979 in San Francisco. The term ``Californian" was a slight exaggeration, as all 23 participants actually lived in San Francisco. Several years later, in 1987, the conference was truly Californian, with 337 participants from all over the state. Since then, the number of participants has been growing like the size of memory chips. In 1993 the conference was renamed the American Conference on Holism (2549 participants), and a second renaming (World Conference on Holism) followed in 1997, when the number of participants from all over the world had grown to 9973. The conference obtained its present name (Galactic Conference on Holism) in 2003 after some discussion as to whether or not the word Galactic was intended to exclude extragalactic life forms. Still the next year, all registered participants were terrestrial-though a few participants positively reported to have sensed extraterrestrial presence.


The number of workshops grew with the number of participants. For the upcoming conference, the organization has to face some down to earth but very nasty scheduling problems. For the 2005 conference the board has decided to have no more than 1000 workshops concurrently. Nevertheless they had to rent every hall or classroom they could lay their hands on. Some of these rooms are available for a restricted time only.


In the morning of the first day the opening meeting takes place in a football stadium, and in the afternoon the participants attend workshops. Before lunch each participant has to indicate which workshop he or she wants to join that afternoon. The organizing staff then has a list of all workshops, including the duration and the number of participants for each workshop. They also have a list of all available rooms, with the capacity of each room, and the time this specific room must be cleared. With this information the staff must schedule each workshop in a room of sufficient capacity and sufficient availability in time. As this problem is not necessarily solvable, some overflow capacity is supplied by tents in the football stadium. These tents have plenty of capacity, but they are unpleasantly warm and noisy. So the organizing staff wants the schedule to minimize the number of tent workshops-that is, workshops that are not assigned to a room. If there are multiple solutions that minimize the number of tent workshops, the staff wants to minimize the number of participants attending tent workshops.


We ask you to supply such a schedule (preferably before lunch is over).

Input 

The input file contains several trials. Each trial consists of two parts: the list of workshops, and the list of rented rooms.


The list of workshops starts with a line containing the number of workshops w (0 < w$ \le$1000). Each of the next w lines contains two numbers, describing a workshop. The first number is the number p of participants(0 < p$ \le$100), and the second number is the duration d of the workshop in minutes (0 < d$ \le$300). For your convenience, other details of the workshops are omitted. All workshops start at 14:00.


The list of rented rooms starts with a line containing the number of rented rooms r (0 < r$ \le$1000). Each of the following r lines contains the description of a rented room. A line describing a rented room contains the number s of seats in the room (0 < s$ \le$100), followed by the time when the room must be cleared, in the format hh : mm where hh represents the hour and mm represents the minute, using a 24-hour clock. All the rooms are available starting at 14:00. All times when rooms must be cleared are between 14:01 and 23:59, inclusive.


The input is terminated by a line consisting of the integer zero.

Output 

For each trial in the input file the output must contain a line consisting of the trial number, the number of tent workshops, and the number of participants attending tent workshops. Follow the format shown in the sample output. Print a blank line after each trial.

Sample Input 

1                  
20 60              
1                  
30 16:00 
2 
20 60 
50 30 
1 
30 14:50 
0

Sample Output 

Trial 1: 0 0

Trial 2: 2 70








#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;

struct info
{
	int p,t;
};
const int MaxW=1000;
const int MaxR=1000;
int w,r,cases,sum_w,sum_p,i,j,l;
info workshop[1100],room[1100];

bool cmp(info x,info y)
{
	return (x.t<y.t);
}

bool init()
{
	int i,hh,mm;
	scanf("%d",&w);
	if(w==0)
		return false;
	sum_w=w;sum_p=0;
	for(i=0;i<w;i++)
	{
		scanf("%d %d",&workshop[i].p,&workshop[i].t);
		sum_p+=workshop[i].p;
	}
	scanf("%d",&r);
	for(i=0;i<r;i++)
	{
		scanf("%d %d:%d",&room[i].p,&hh,&mm);
		room[i].t=(hh-14)*60+mm;
	}
	sort(workshop,workshop+w,cmp);
	sort(room,room+r,cmp);
	return true;
}

int main()
{
	cases=0;
	while(init())
	{
		for(i=0;i<r;i++)
		{
			l=-1;
			for(j=0;j<w;j++)
				if(workshop[j].t>room[i].t)
					break;
				else if(workshop[j].p<=room[i].p&&workshop[j].p>=0)
				{
					if(l<0||workshop[l].p<workshop[j].p)
						l=j;
				}
			if(l>=0)
			{
				sum_w--;
				sum_p-=workshop[l].p;
				workshop[l].p=-1;
			}
		}
		printf("Trial %d: %d %d\n\n",++cases,sum_w,sum_p);
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值