码迷,mamicode.com
首页 > 其他好文 > 详细

UVA11559 Event Planning【水题】

时间:2019-02-10 09:37:25      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:sid   collect   tor   包括   sts   test   planning   const   des   

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: 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
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.
Sample Input
3 1000 2 3
200
0 2 2
300
27 3 20
5 2000 2 4
300
4 3 0 4
450
7 8 0 13
Sample Output
900
stay home

问题链接UVA11559 Event Planning
问题简述:(略)
问题分析
????组织旅游,需要根据参与人数、预算、酒店及其周末空余床位的情况,决定是否成行。输入包括旅游人数N(1<=N<=200),预算B(1<=B<=500000),可供考虑的酒店数量H(1<=H<=18),可选择的出行周末W(1<=W<=13)。其中H确定之后,会输入H组数据,每两行为一组,第一行表示该酒店的人均住店费用p(1<=p<=10000),第二行表示W个周末对应每个周末该酒店的床位空余情况a(0<=a<=1000)。
????需要计算最低的预算,如果最低预算超过给定值则呆在家里“stay home”。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* UVA11559 Event Planning */

#include <bits/stdc++.h>

using namespace std;

const int H = 18;
const int W = 13;
int p[H];
int a[H][W];

int main()
{
    int n, b, h, w;
    while(scanf("%d%d%d%d", &n, &b, &h, &w) != EOF) {
        for(int i = 0; i < h; i++) {
            scanf("%d", &p[i]);
            for(int j = 0; j < w; j++)
                scanf("%d", &a[i][j]);
        }

        int minb = INT_MAX;
        for(int j = 0; j < w; j++)
            for(int i = 0; i < h; i++)
                if(a[i][j] >= n && p[i] * n < minb)
                    minb = p[i] * n;

        if(minb > b)
            printf("stay home\n");
        else
            printf("%d\n", minb);
    }

    return 0;
}

UVA11559 Event Planning【水题】

标签:sid   collect   tor   包括   sts   test   planning   const   des   

原文地址:https://www.cnblogs.com/tigerisland45/p/10358605.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!