第十二届浙江省大学生程序设计大赛-Lunch Time
2015-06-26 14:30
218 查看
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 S, M and D (1 <= S, M, D <= 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
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 S, M and D (1 <= S, M, D <= 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
#include <iostream> #include <string> #include <stdio.h> #include<algorithm> using namespace std; struct node { string s; int result; }ap[110],ma[110],de[110]; bool cmp(node a,node b) { return a.result<b.result; } int main() { int T,S,M,D,i,s,m,d; int sum; scanf("%d",&T); while(T--) { scanf("%d %d %d",&S,&M,&D); sum=0; for(i=0;i<S;i++) { cin>>ap[i].s>>ap[i].result; } for(i=0;i<M;i++) { cin>>ma[i].s>>ma[i].result; } for(i=0;i<D;i++) { cin>>de[i].s>>de[i].result; } sort(ap,ap+S,cmp); sort(ma,ma+M,cmp); sort(de,de+D,cmp); if(S%2==0) { int ss=S/2; if(ap[ss].result>ap[ss-1].result) { sum+=ap[ss].result; s=ss; } else { sum+=ap[ss-1].result; s=ss-1; } } else { sum+=ap[S/2].result; s=S/2; } if(M%2==0) { int ss=M/2; if(ma[ss].result>ma[ss-1].result) { sum+=ma[ss].result; m=ss; } else { sum+=ma[ss-1].result; m=ss-1; } } else { sum+=ma[M/2].result; m=M/2; } if(D%2==0) { int ss=D/2; if(de[ss].result>de[ss-1].result) { sum+=de[ss].result; d=ss; } else { sum+=de[ss-1].result; d=ss-1; } } else { sum+=de[D/2].result; d=D/2; } cout<<sum<<" "<<ap[s].s<<" "<<ma[m].s<<" "<<de[d].s<<endl; } return 0; }
相关文章推荐
- MyEclipse 注册码(包含6.5-8.5)
- 第十二届浙江省大学生程序设计大赛-Lunch Time 分类: 比赛 2015-06-26 14:30 5人阅读 评论(0) 收藏
- Deep Learning(深度学习)学习笔记整理系列之(一)
- [LeetCode] Summary Ranges
- 学习日记-三大特性之多态
- syntax error near unexpected token ?怎么解决
- 机器人局部避障的动态窗口法(dynamic window approach) (转)
- 如何让vim编辑器永久显示行号
- 二叉树中和为某一值的路径
- Android视图SurfaceView
- TNS-12564: TNS:connection refused
- openwebrtc(1) 服务端和android客户端demo安装
- Mac快捷键指南
- 清除微信浏览器缓存
- HTML模块化:使用HTML5 Boilerplate模板
- Java String详解
- SAT写作重要方法之体会英文名著观察生活
- 第十二届浙江省大学生程序设计大赛-Beauty of Array
- 第十二届浙江省大学生程序设计大赛-Beauty of Array 分类: 比赛 2015-06-26 14:27 12人阅读 评论(0) 收藏
- enum Qt::AspetRatioMode