http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5499

The 12th Zhejiang Provincial Collegiate Programming Contest - G
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

  1. 2
  2. 1 3 2
  3. Fresh_Cucumber 4
  4. Chow_Mein 5
  5. Rice_Served_with_Duck_Leg 12
  6. Fried_Vermicelli 7
  7. Steamed_Dumpling 3
  8. Steamed_Stuffed_Bun 4
  9. 2 3 1
  10. Stir-fried_Loofah_with_Dried_Bamboo_Shoot 33
  11. West_Lake_Water_Shield_Soup 36
  12. DongPo's_Braised_Pork 54
  13. West_Lake_Fish_in_Vinegar 48
  14. Longjing_Shrimp 188
  15. DongPo's_Crisp 18

Sample Output

  1. 15 Fresh_Cucumber Fried_Vermicelli Steamed_Stuffed_Bun
  2. 108 West_Lake_Water_Shield_Soup DongPo's_Braised_Pork DongPo's_Crisp

分析:

  1. 输入三个数,分别代表三个食物数量。按顺序输入每个东西的名字与质量,然后对于每种食物质量为中位数的加起来,最后输出。

直接结构体排序,输出中间的那个,如果是偶数输出中间较大者,

  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stack>
  5. #include <queue>
  6. #include <map>
  7. #include <set>
  8. #include <vector>
  9. #include <math.h>
  10. #include <algorithm>
  11. using namespace std;
  12. #define ls 2*i
  13. #define rs 2*i+1
  14. #define up(i,x,y) for(i=x;i<=y;i++)
  15. #define down(i,x,y) for(i=x;i>=y;i--)
  16. #define mem(a,x) memset(a,x,sizeof(a))
  17. #define w(a) while(a)
  18. #define LL long long
  19. const double pi = acos(-1.0);
  20. #define Len 20005
  21. #define mod 19999997
  22. const int INF = 0x3f3f3f3f;
  23.  
  24. int t,a,b,c;
  25.  
  26. struct node
  27. {
  28. char name[];
  29. int num;
  30. }s[][];
  31.  
  32. int cmp(node a,node b)
  33. {
  34. return a.num<b.num;
  35. }
  36.  
  37. int main()
  38. {
  39. int i,j,k;
  40. scanf("%d",&t);
  41. w(t--)
  42. {
  43. scanf("%d%d%d",&a,&b,&c);
  44. up(i,,a-)
  45. scanf("%s%d",s[][i].name,&s[][i].num);
  46. up(i,,b-)
  47. scanf("%s%d",s[][i].name,&s[][i].num);
  48. up(i,,c-)
  49. scanf("%s%d",s[][i].name,&s[][i].num);
  50. sort(s[],s[]+a,cmp);
  51. sort(s[],s[]+b,cmp);
  52. sort(s[],s[]+c,cmp);
  53. int ans=s[][a/].num+s[][b/].num+s[][c/].num;
  54. printf("%d %s %s %s\n",ans,s[][a/].name,s[][b/].name,s[][c/].name);
  55. }
  56.  
  57. return ;
  58. }

zoj The 12th Zhejiang Provincial Collegiate Programming Contest Lunch Time的更多相关文章

  1. zoj The 12th Zhejiang Provincial Collegiate Programming Contest Capture the Flag

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5503 The 12th Zhejiang Provincial ...

  2. zoj The 12th Zhejiang Provincial Collegiate Programming Contest Team Formation

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5494 The 12th Zhejiang Provincial ...

  3. zoj The 12th Zhejiang Provincial Collegiate Programming Contest Beauty of Array

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5496 The 12th Zhejiang Provincial ...

  4. zoj The 12th Zhejiang Provincial Collegiate Programming Contest Convert QWERTY to Dvorak

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5502  The 12th Zhejiang Provincial ...

  5. zoj The 12th Zhejiang Provincial Collegiate Programming Contest May Day Holiday

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5500 The 12th Zhejiang Provincial ...

  6. zoj The 12th Zhejiang Provincial Collegiate Programming Contest Demacia of the Ancients

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5504  The 12th Zhejiang Provincial ...

  7. zjuoj The 12th Zhejiang Provincial Collegiate Programming Contest Ace of Aces

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5493 The 12th Zhejiang Provincial ...

  8. 140 - The 12th Zhejiang Provincial Collegiate Programming Contest(第二部分)

    Floor Function Time Limit: 10 Seconds      Memory Limit: 65536 KB a, b, c and d are all positive int ...

  9. 140 - The 12th Zhejiang Provincial Collegiate Programming Contest(浙江省赛2015)

      Ace of Aces Time Limit: 2 Seconds      Memory Limit: 65536 KB There is a mysterious organization c ...

随机推荐

  1. PureBasic 读取文件中一行的两个数据例子

    , "Test1.txt") ; if the file could be read, we continue... , "Test2.txt") ) = ; ...

  2. php四个常用类封装 :MySQL类、 分页类、缩略图类、上传类;;分页例子;

    Mysql类 <?php /** * Mysql类 */ class Mysql{ private static $link = null;//数据库连接 /** * 私有的构造方法 */ pr ...

  3. php apc

    APC,全称是Alternative PHP Cache,官方翻译叫”可选PHP缓存”.它为我们提供了缓存和优化PHP的中间代码的框架. APC的缓存分两部分:系统缓存和用户数据缓存. 系统缓存 它是 ...

  4. ASP.NET MVC 4下 Code First 数据库迁移

     一.命令开启 1.打开控制台:视图->其他窗口->程序包管理器控制台: 2.启动数据库迁移,执行命令:enable-migrations 创建成功后会新增migrations目录等. 若 ...

  5. asp.net字符串的数学表达式计算结果

    using System; using System.Collections.Generic; using System.Web; using System.CodeDom.Compiler; usi ...

  6. hdu1045 Fire Net

    在一张地图上建立碉堡(X),要求每行没列不能放两个,除非中间有强挡着.求最多能放多少个碉堡 #include<iostream> #include<cstdio> #inclu ...

  7. iOS Node Conflict svn冲突

    当出现这个冲突时,应该是我add的文件,和同事处理的方法有冲突导致的. 这个的解决办法是:先revert这个文件,然后再update.

  8. 将Excel导入SQL Server 只能导入数字,其他数据变为NULL怎么解决?

    先新建一个TXT文件,把数据粘贴进去 再新建一个Excel文件,在菜单栏中选Data再选From Text 找到txt文件,点import 一定要选Text 点Finish,点OK. 接下来在往数据库 ...

  9. 开始了ecshop

    一个多星期前开始接触ecshop,突然决定要用它来做网站,于是从网上找各种手册与视频,联系官网客服,然后知道官网一共提供三种类型的服务,一种是ecshop授权,不包含任何技术支持,第二种是易开店的标准 ...

  10. https://my.oschina.net/reesechou/blog/492265

    https://my.oschina.net/reesechou/blog/492265