Lunch Time

来源:互联网 发布:游戏变速器源码 编辑:程序博客网 时间:2024/05/26 22:06

Lunch Time

 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

21 3 2Fresh_Cucumber 4Chow_Mein 5Rice_Served_with_Duck_Leg 12Fried_Vermicelli 7Steamed_Dumpling 3Steamed_Stuffed_Bun 42 3 1Stir-fried_Loofah_with_Dried_Bamboo_Shoot 33West_Lake_Water_Shield_Soup 36DongPo's_Braised_Pork 54West_Lake_Fish_in_Vinegar 48Longjing_Shrimp 188DongPo's_Crisp 18

Sample Output

15 Fresh_Cucumber Fried_Vermicelli Steamed_Stuffed_Bun108 West_Lake_Water_Shield_Soup DongPo's_Braised_Pork DongPo's_Crisp

Think:选餐问题,输入的三个数代表接下来几行是同一类型的食物,之后选择每种食物价格中间的,如果中间价格有两个就选最大的。

#include <stdio.h>#include <string.h>struct node{    int x;    char s[11100];}a[1100],tt;char ss[1100][1100];int main(){    int t;    int n,m,k;    scanf("%d",&t);    while(t--){    int xx=0;    int sum=0;        scanf("%d%d%d",&n,&m,&k);        for (int i=0;i<n;i++){            //getchar();            scanf("%s %d",a[i].s,&a[i].x);        }        for (int i=0;i<n;i++){            for (int j=i+1;j<n;j++){                if(a[i].x>a[j].x){                    tt=a[i];                    a[i]=a[j];                    a[j]=tt;                }            }        }        if (n%2!=0){            strcpy(ss[xx++],a[n/2].s);            sum+=a[n/2].x;        }        else{           strcpy(ss[xx++],a[n/2].s);            sum+=a[n/2].x;        }        for (int i=0;i<m;i++){            //getchar();            scanf("%s %d",a[i].s,&a[i].x);        }        for (int i=0;i<m;i++){            for (int j=i+1;j<m;j++){                if(a[i].x>a[j].x){                    tt=a[i];                    a[i]=a[j];                    a[j]=tt;                }            }        }        if (m%2!=0){            strcpy(ss[xx++],a[m/2].s);            sum+=a[m/2].x;        }        else{            strcpy(ss[xx++],a[m/2].s);            sum+=a[m/2].x;        }        for (int i=0;i<k;i++){            //getchar();            scanf("%s %d",a[i].s,&a[i].x);        }        for (int i=0;i<k;i++){            for (int j=i+1;j<k;j++){                if(a[i].x>a[j].x){                    tt=a[i];                    a[i]=a[j];                    a[j]=tt;                }            }        }        if (k%2!=0){            strcpy(ss[xx++],a[k/2].s);            sum+=a[k/2].x;        }        else{            strcpy(ss[xx++],a[k/2].s);            sum+=a[k/2].x;        }        printf("%d",sum);        for (int i=0;i<xx;i++){            printf(" %s",ss[i]);        }        printf("\n");    }    return 0;}
0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 怀孕七个月胎位不正怎么办 怀孕肚子上有妊娠纹怎么办 怀孕九个月肚子长痱子怎么办 怀孕前体重偏胖怎么办 怀孕打胰岛素血糖控制不好怎么办 孕后期憋的难受怎么办 怀孕6个月不想生怎么办 孕六个月不想要怎么办 怀孕9个月喝酒了怎么办 怀孕8个月喝醉了怎么办 怀孕6个月胃酸烧心怎么办 怀孕7个月胃酸怎么办 怀孕5个月胃酸怎么办 怀孕2个月胃酸怎么办 怀孕六个月胃酸烧心怎么办 孕六个月反胃酸怎么办 怀孕三个月胃酸吐酸水怎么办 孕六个月胃难受怎么办 孕6个月胃酸厉害怎么办 孕妇6个月胃酸怎么办 孕早期胎盘早剥怎么办 孕妇晕车怎么办最有效方法 怀孕了受凉胃疼怎么办 怀孕4个月胎位低怎么办 6个月胎位低怎么办 7个多月了胎位低怎么办 瑜伽按摩球破了怎么办 孕妇吐完胸口疼怎么办 孕25周胸口堵怎么办呢 孕期没做过产检怎么办 宝宝的泪囊堵塞怎么办 瑜伽球塞子丢了怎么办 瑜伽球塞子没了怎么办 练阴瑜伽是想睡怎么办 肠道引流拨断了怎么办 瑜伽动作做不到位怎么办 胃肠吸收不好一直长不胖怎么办 小孩把泡泡糖吞进肚子怎么办 练习瑜伽又?带硬怎么办 天气太热没有空调怎么办 腹股沟岔气怎么办才能快点好