ZOJ 3875 Lunch Time (The 12th Zhejiang Provincial Collegiate Programming Contest )

题目链接】:click here~~

题目大意】给出一些点心的单价和数量,求出中位数单价的点心

解题思路】排序一遍,取中位数就可以了

代码:

#include<bits/stdc++.h>
using namespace std;
struct node{
    char ch[100];
    int value;
} dish[100000],a,b,c;
int T;
bool cmp(node a,node b){
    return a.value<b.value;
}
int main()
{
    cin>>T;
    while(T--)
    {
        int n,m,k;
        cin>>n>>m>>k;
        for(int i=0; i<n; i++) scanf("%s%d",dish[i].ch,&dish[i].value);
        sort(dish,dish+n,cmp);
        a=dish[(n)/2];
        for(int i=0; i<m; i++) scanf("%s%d",dish[i].ch,&dish[i].value);
        sort(dish,dish+m,cmp);
        b=dish[(m)/2];
        for(int i=0; i<k; i++) scanf("%s%d",dish[i].ch,&dish[i].value);
        sort(dish,dish+k,cmp);
        c=dish[(k)/2];
        printf("%d ",a.value+b.value+c.value);
        printf("%s %s %s\n",a.ch,b.ch,c.ch);
    }
    return 0;
}



你可能感兴趣的:(ACM,比赛题)