ACM刷题之ZOJ————Lunch Time

本文介绍了ZOJ上的Lunch Time问题,该问题要求帮助Edward选择一道中位价格的开胃菜、主菜和甜点。输入包含多个测试用例,每个用例给出每种类型的菜品数量和价格。输出为中位价格餐品的总价格及名称。题目提供样例输入和输出,适合ACM竞赛训练。
摘要由CSDN通过智能技术生成
Lunch Time

Time Limit: 2 Seconds       Memory Limit: 65536 KB

The 999th Zhejiang Provincial Collegiate Programming Contest will be held in Marjar University. The canteen of Marjar University is making preparations for this grand competition. The canteen provides a lunch set of three types: appetizer, main course and dessert. Each type has several dishes with different prices for choosing.

Edward is the headmaster of Marjar University. One day, to inspect the quality of dishes, he go to the canteen and decides to choose a median set for his lunch. That means he must choose one dish from each of appetizers, main courses and desserts. Each chosen dish should at the median price among all dishes of the same type.

For example, if there are five dessert dishes selling at the price of 2, 3, 5, 10, 30, Edward should choose the dish with price 5 as his dessert since its price is located at the median place of the dessert type. If the number of dishes of a type is even, Edward will choose the dish which is more expensive among the two medians.

You are given the list of all dishes, please write a program to help Edward decide which dishes he should choose.

Input

There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:

The first line contains three integers SM and D (1 <= SMD <= 100), which means that there are S dishes of appetizer, M dishes of main course and D dishes of dessert.

Then followed by three parts. The first part contains S lines, the second and the last part contains M and D lines respectively. In each line of the three parts, there is a string and an integer indicating the name and the price of a dish. The name of dishes will only consist of non-whitespace characters with no more than 50 characters. The price of dishes are non-negative integers less than or equal to 1000. All dish names will be distinct.

Output

For each test case, output the total price of the median set, together with the names of appetizer, main course and dessert, separated by a single space.

Sample Input
2
1 3 2
Fresh_Cucumber 4
Chow_Mein 5
Rice_Served_with_Duck_Leg 12
Fried_Vermicelli 7
Steamed_Dumpling 3
Steamed_Stuffed_Bun 4
2 3 1
Stir-fried_Loofah_with_Dried_Bamboo_Shoot 33
West_Lake_Water_Shield_Soup 36
DongPo's_Braised_Pork 54
West_Lake_Fish_in_Vinegar 48
Longjing_Shrimp 188
DongPo's_Crisp 18
Sample Output
15 Fresh_Cucumber Fried_Vermicelli Steamed_Stuffed_Bun
108 West_Lake_Water_Shield_Soup DongPo's_Braised_Pork DongPo's_Crisp
 
水题
找出中位数即可,我这里放了两个数组里,用sort排序后找中位数
 
下面是ac代码
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<string>
#include<iostream>
using namespace std;
#define MID(x,y) ((x+y)>>1)
#define CLR(arr,val) memset(arr,val,sizeof(arr))
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);
const double PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int N=2e5+7;

char a1[222][1001];
char a2[222][1001];
char a3[222][1001];

int b[4][1001];
int b1[1001];
int b2[1001];
int b3[1001];

int main()
{
	//freopen("f:/input.txt", "r", stdin);
	int zu,s,m,d,i,j,k,n,mid1,mid2,mid3;
	scanf("%d",&zu);
	while(zu--)
	{
		scanf("%d%d%d",&s,&m,&d);
		for(i=0;i<s;i++)
		{
			scanf("%s %d",a1[i],&b[1][i]);
			b1[i]=b[1][i];
		}
		for(i=0;i<m;i++)
		{
			scanf("%s %d",a2[i],&b[2][i]);
			b2[i]=b[2][i];
		}
		
		for(i=0;i<d;i++)
		{
			scanf("%s %d",a3[i],&b[3][i]);
			b3[i]=b[3][i];
		}
		sort(b1,b1+s);
		sort(b2,b2+m);
		sort(b3,b3+d);
		mid1=(s/2);
		
		mid2=(m/2);
		
		mid3 = (d/2);
		
		mid1=b1[mid1];
		
		mid2=b2[mid2];
		
		mid3=b3[mid3];
		
		printf("%d ",mid1+mid2+mid3);
		
		for(i=0;i<s;i++)
		{
			if(b[1][i]==mid1)
			{
				printf("%s ",a1[i]);
				break;
			}
		}
		
		for(i=0;i<m;i++)
		{
			if(b[2][i]==mid2)
			{
				printf("%s ",a2[i]);
				break;
			}
		}
		
		for(i=0;i<d;i++)
		{
			if(b[3][i]==mid3)
			{
				printf("%s\n",a3[i]);
				break;
			}
		}
		
		
		
	}
}



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值