toj 3098 Event Planning

本文提供了一道名为“活动策划”的编程竞赛题目的解题思路。题目要求在预算范围内为一群成员找到合适的住宿酒店,并提供了酒店的价格及可用床位等信息。通过分析输入数据并进行筛选、排序,最终确定最经济的住宿方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

3098.   Event Planning
Time Limit: 5.0 Seconds    Memory Limit: 65536K
Total Runs: 134    Accepted Runs: 67    Multiple test files



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 first line of input consists of four integers: 1 ≤ N ≤ 200, the number of participants, 1 ≤ B ≤ 500000, the budget, 1 ≤ H ≤ 18, the number of hotels to consider, and 1 ≤ W ≤ 13, the number of weeks you can choose between. Then follow two lines for each of the H hotels. The first gives 1 ≤ p ≤ 10000, the price for one person staying the weekend at the hotel. The second contains W integers, 0 ≤ a ≤ 1000, giving the number of available beds for each weekend at the hotel.

Output

Output the minimum cost of the stay for your group, or "stay home" if nothing can be found within the budget.

Sample Input

3 1000 2 3
200
0 2 2
300
27 3 20

Sample Output

900

Sample Input 2

5 2000 2 4
300
4 3 0 4
450
7 8 0 13

Sample Output 2

stay home


Source: Nordic Collegiate Contest 2008
Submit   List    Runs   Forum   Statistics

#include  < iostream >
#include 
< algorithm >
#define  MAX 10000
using   namespace  std;
int  data[MAX];
bool  comp( int  a, int  b)
{
    
return  a < b;
}
int  n,b,h,w;
int  main()
{
    
int  i,j,a;
    
while (scanf( " %d%d%d%d " , & n, & b, & h, & w) != EOF)
    {
        
int  k = 0 ,m;
        
for (i = 0 ;i < h;i ++ )
        {
            scanf(
" %d " , & a);
            
for (j = 0 ;j < w;j ++ )
            {
                scanf(
" %d " , & m);
                
if (m < n)
                    
continue ;
                
if (n * a > b)
                    
continue ;
                data[k
++ ] = n * a;
            }
        }
        sort(data,data
+ k,comp);
        
if (k == 0 )
            printf(
" stay home\n " );
        
else
            printf(
" %d\n " ,data[ 0 ]);
    }
    
return   0 ;
}

转载于:https://www.cnblogs.com/forever4444/archive/2009/05/20/1471066.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值