UVa 11559 Event Planning

5 篇文章 0 订阅

Source: UVa OJ

As you didn't show up to the yearly general meeting of the Nordic Club of Pin Collectors, you were unanimously elected to organize this years excursion to Pin City. You are free to choose from a number of weekends this autumn, and have to find a suitable hotel to stay at, preferably as cheap as possible.

You have some constraints: The total cost of the trip must be within budget, of course. All participants must stay at the same hotel, to avoid last years catastrophe, where some members got lost in the city, never being seen again.

Input

The input file contains several test cases, each of them as described below.

The first line of input consists of four integers: $ \leq$ N $ \leq$ 200 , the number of participants, $ \leq$ B $ \leq$ 500000 , the budget, $ \leq$ H $ \leq$ 18 , the number of hotels to consider, and $ \leq$ W $ \leq$ 13 , the number of weeks you can choose between. Then follow two lines for each of the H hotels. The first gives $ \leq$ p $ \leq$ 10000 , the price for one person staying the weekend at the hotel. The second contains W integers, $ \leq$ a $ \leq$ 1000 , giving the number of available beds for each weekend at the hotel.

Output

For each test case, write to the output the minimum cost of the stay for your group, or ``stay home'' if nothing can be found within the budget, on a line by itself.

Analysis

This question is a simply ad hoc question. We just need to simply read all the data by a loop and then compare to get the minimum cost. Note that we don't need to store the price and number of bed available in array, as we don't need to reuse those data again. We only need to decide three things in each loop: 1. Enough money? 2. Enough beds? 3. Is the cost the smallest when compared to previous hotels?


#include <iostream>
using namespace std;

int main()
{
	int N; // number of participants
	int B; // budget
	int H; // number of hotels
	int W; // number of weeks to be considered
	int price;
	int numOfBeds;
	int minCost;

	while( cin >> N >> B >> H >> W )
	{
		minCost = B+1; // set to an impossible value
		for( int i=0; i<H; i++ )
		{
			bool enoughMoney = false;
			bool enoughBed = false;
			int cost;

			cin >> price;
			cost = price*N;
			if( cost <= B ) enoughMoney = true;

			for( int j=0; j<W; j++ )
			{
				cin >> numOfBeds;
				if( numOfBeds >= N ) enoughBed = true;
			}

			if( enoughMoney && enoughBed && cost<minCost ) minCost = cost;
		}

		if( minCost <= B ) cout << minCost << endl;
		else cout << "stay home" << endl;
	}

	return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值