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
题意:有3种物品,每种物品分别有S,M,D个,每个有一个名字,和ID,要求对每种物品的id从小到大排序
然后去中间的那个如果偶数个,则去中间偏后的那个输出id和和他们的名字
解题思路:这个题只需对每种物品排下需就行了这里我用vector容器存储
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <cmath>
#include <algorithm>
#define pb push_back
#define mk make_pair
typedef long long ll;
using namespace std;
struct node
{
int m;string s;
node(string s,int m):s(s),m(m){}
/*bool operator<(node &a)const
{
m<a.m;
}*/
};
bool cmp(node a,node b)
{
return a.m<b.m;
}
vector<node>q[3];
int main()
{
int t;cin>>t;
while(t--)
{
int a,b,c;cin>>a>>b>>c;
q[0].clear();q[1].clear();q[2].clear();
for(int i=0;i<a;i++)
{
string s;int h;cin>>s>>h;
q[0].pb(node(s,h));
}
for(int i=0;i<b;i++)
{
string s;int h;cin>>s>>h;
q[1].pb(node(s,h));
}
for(int i=0;i<c;i++)
{
string s;int h;cin>>s>>h;
q[2].pb(node(s,h));
}
sort(q[0].begin(),q[0].end(),cmp);
sort(q[1].begin(),q[1].end(),cmp);
sort(q[2].begin(),q[2].end(),cmp);
int ans=0;
/*cout<<"+++++++++++"<<endl;
for(int i=0;i<q[1].size();i++)cout<<q[1][i].s<<" "<<q[1][i].m<<endl;*/
for(int i=0;i<3;i++)
{
int m=q[i].size();
//if(m%2)ans+=q[i][m/2+1].m;
//else
ans+=q[i][m/2].m;
}
cout<<ans;
for(int i=0;i<3;i++)
{
int m=q[i].size();
//if(m%2)
cout<<" "<<q[i][m/2].s;
//else cout<<" "<<q[i][m/2].s;
}
cout<<endl;
}
return 0;
}
本文介绍了一道编程竞赛题目,题目要求根据提供的菜品名称和价格列表,选择三种类型的菜品(开胃菜、主菜、甜点)中价格位于中位数的菜品组合。文章详细解释了解题思路和步骤,并提供了完整的C++代码实现。
129

被折叠的 条评论
为什么被折叠?



