170411 VJ题解(2)(ZOJ
来源:互联网 发布:软件版权声明 编辑:程序博客网 时间:2024/05/16 16:16
本作品采用知识共享署名-相同方式共享 4.0 国际许可协议进行许可。
题目地址: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3875
思路
本题考察结构体的应用。将所输入的菜名及其价格按价格从低到高排列,利用C语言中整数除法向下取整的特性,取每种菜的第 N/2+1 道菜,最后输出三道菜的总价及各自的名称。
需要注意的地方
1.取 N/2+1 的前提是存储菜的数据时从 “1” 而不是从 “0” 开始。2.本题数据量小,排序方式随意。
Show me the code
#include <bits/stdc++.h>using namespace std;typedef struct node{ char name[505]; int price;} snode;bool cmp(snode x, snode y){ return x.price < y.price;}int main(){ int m, n, t, s, d, c; snode a[1001]; while(cin >> t) { while(t--) { memset(a, 0, sizeof(a)); snode b[3]; cin >> s >> m >> d; for(int i = 1; i <= s; i++) { cin >> a[i].name >> a[i].price; } sort(a + 1, a + s + 1, cmp); b[0] = a[s / 2 + 1]; c = b[0].price; for(int i = 1; i <= m; i++) { cin >> a[i].name >> a[i].price; } sort(a + 1, a + m + 1, cmp); b[1] = a[m / 2 + 1]; c += b[1].price; for(int i = 1; i <= d; i++) { cin >> a[i].name >> a[i].price; } sort(a + 1, a + d + 1, cmp); b[2] = a[d / 2 + 1]; c += b[2].price; cout << c << " " << b[0].name << " " << b[1].name << " " << b[2].name << endl; } }}
0 0
- 170411 VJ题解(2)(ZOJ
- 170411 VJ题解(1)(ZOJ
- 170411 VJ题解(3)(ZOJ
- 170411 VJ题解(4)(ZOJ
- 170411 VJ题解(5)(ZOJ
- 模拟测试(vj)
- VJ pet(DFS)
- ZOJ题解
- VJ匿名虐(1)
- vj-苹果(01背包)
- zoj 1871 steps 题解(数学)
- 走近人脸检测(2)——VJ人脸检测器及其发展
- SDUT-VJ-Wormholes(Bellman算法)
- VJ组队赛->Chip Factory(5536)
- VJ组队赛->House Building(5538)
- zoj 1387 译题+题解
- zoj 1438 - Asteroids! 题解
- zoj--1089--Lotto题解
- 应用程序多语言设置
- jquery内外部插入
- js检测文件类型
- (转)华兴资本包凡:我们这么屌,是有原因的
- 装最多水的容器
- 170411 VJ题解(2)(ZOJ
- 谷歌Inception网络中的Inception-V3到Inception-V4具体作了哪些优化?
- 51nod 1270 数组的最大代价
- 关于去除表单选中时的蓝色边框和设置内置提示字体
- 10-进程间通信-有名管道FIFO(功能:传输数据)
- HDU 2082 找单词 母函数
- JSON和GSON学习
- Bean named 'transactionAdvice' must be of type [org.aopalliance.aop.Advice], but was actually of typ
- bmon:Linux 下一个强大的网络带宽监视和调试工具