uva11559 Event Planning

uva11559

uDebug11559

题意是说,作为一次短途旅行的组织者,你需要根据参与人数、预算、酒店及其周末空余床位的情况,决定是否成行。其中旅游人数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,否则就输出记录的那个更低的预算。

python版本AC代码

H = [0 for _ in range(18)]
W = [[0 for col in range(13)] for row in range(18)]

while True:
	try:
		N,Budget,Hotel, Week = map(int,input().split())
	except Exception as e:
		break
	MinBudget = 500001
	for i in range(Hotel):
		H[i] = int(input())
		WeekList = input().split()
		for j in range(Week):
			W[i][j] = int(WeekList[j])
			if W[i][j] >= N:
				if N*H[i] <= Budget and MinBudget > N*H[i]:
					MinBudget = N*H[i]
	if MinBudget == 500001:
		print('stay home')
	else:
		print(MinBudget)


C++版本AC代码

#include <iostream>
#include<cstdio>
using namespace std;

//#define ZANGFONG
int H[18],W[18][13];

int main()
{
    #ifdef ZANGFONG
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif // ZANGFONG
    int N,Budget,Hno,Wno,i,j,MinBudget;
    while(scanf("%d%d%d%d\n",&N,&Budget,&Hno,&Wno)!= EOF)
    {
        MinBudget = 500001;
        for(i = 0; i < Hno; i++)
        {
            scanf("%d\n",&H[i]);
            for(j = 0; j < Wno; j++)
            {
                scanf("%d",&W[i][j]);
                if(W[i][j]>=N)
                {
                    if(N*H[i] <=Budget && MinBudget > N*H[i]) MinBudget = N*H[i];
                }
            }
        }
        if(MinBudget == 500001) printf("stay home\n");
        else printf("%d\n",MinBudget);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/zangfong/article/details/82919616