当前位置:网站首页>L2-009 抢红包 (25 分)(结构体+自定义排序)
L2-009 抢红包 (25 分)(结构体+自定义排序)
2022-08-08 16:51:00 【Here_SDUT】
没有人没抢过红包吧…… 这里给出 N 个人之间互相发红包、抢红包的记录,请你统计一下他们抢红包的收获。
输入格式: 输入第一行给出一个正整数 N(≤10^4),即参与发红包和抢红包的总人数,则这些人从 1 到 N 编号。随后 N 行,第 i 行给出编号为 i 的人发红包的记录,格式如下:
K N_1 P_1 … N_K P_K
其中 K(0≤K≤20)是发出去的红包个数,N_i 是抢到红包的人的编号,P_i(>0)
输出格式: 按照收入金额从高到低的递减顺序输出每个人的编号和收入金额(以元为单位,输出小数点后2位)。每个人的信息占一行,两数字间有1个空格。如果收入金额有并列,则按抢到红包的个数递减输出;如果还有并列,则按个人编号递增输出。
输入样例:
10
3 2 22 10 58 8 125
5 1 345 3 211 5 233 7 13 8 101
1 7 8800
2 1 1000 2 1000
2 4 250 10 320
6 5 11 9 22 8 33 7 44 10 55 4 2
1 3 8800
2 1 23 2 123
1 8 250
4 2 121 4 516 7 112 9 10
输出样例:
1 11.63
2 3.63
8 3.63
3 2.11
7 1.69
6 -1.67
9 -2.18
10 -3.26
5 -3.26
4 -12.32
分析 就是细节题,题目让你干什么就干什么。
代码
// _ooOoo_
// o8888888o
// 88" . "88
// (| -_- |)
// O\ = /O
// ____/`---'\____
// . ' \| |// `.
// / \||| : |||// \
// / _||||| -:- |||||- \
// | | \\ - /// | |
// | \_| ''\---/'' | |
// \ .-\__ `-` ___/-. /
// ___`. .' /--.--\ `. . __
// ."" '< `.___\_<|>_/___.' >'"".
// | | : `- \`.;`\ _ /`;.`/ - ` : | |
// \ \ `-. \_ __\ /__ _/ .-` / /
// ======`-.____`-.___\_____/___.-`____.-'======
// `=---='
//
// .............................................
// 佛祖保佑 一发AC 永无BUG
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn = 1e5+10;
const int inf = 0x3f3f3f3f;
const double PI = acos(-1.0);
typedef pair<int,int> PII;
struct node {
int money, cnt, id;
const bool operator < (const node &t) const{
if(money == t.money) {
if(cnt == t.cnt) return id < t.id;
return cnt > t.cnt;
}
return money > t.money;
}
}a[maxn];
int main(int argc, char const *argv[]) {
int n, k, x, y;
cin >> n;
for(int i = 1; i <= n; i++) {
a[i].id = i;
cin >> k;
while(k--) {
cin >> x >> y;
a[x].cnt++;
a[x].money += y;
a[i].money -= y;
}
}
sort(a+1, a+1+n);
for(int i = 1; i <= n; i++) printf("%d %.2lf\n",a[i].id, a[i].money*1.0/100);
return 0;
}
边栏推荐
- ggplot2可视化水平箱图并使用fct_reorder排序数据、使用na.rm处理缺失值(reorder boxplot with fct_reorder)、按照箱图的中位数从大到小排序水平箱图
- Patience sorting - specializing in quickly solving the longest increasing subarray
- vi编辑器命令
- 差分约束做法
- [机缘参悟-64]:《兵者,诡道也》-5-孙子兵法解读-混战计
- 中金财富开户安全吗?怎么操作?
- Acwing Week 63 [Unfinished]
- iNFTnews | 元宇宙为企业发展带来新思路
- leetcode 155. Min Stack最小栈(中等)
- Photoshop2021安装教程
猜你喜欢
The realization of the salary slip issuing function of WeChat public account + web background
元宇宙医疗或将改变医疗格局
高数_证明_基本初等函数的导数公式
通俗易懂的epoll
【LeetCode】试题总结:深度优先搜索 (DFS)
QCon 回顾 | Data Fabric:逻辑统一、物理分散
Acwing第 63 场周赛【未完结】
4. S32K14X study notes: S32 Design Studio new and imported projects
JVM内存Dump原理与在线分析实战
信号生成和可视化
随机推荐
[uniapp applet] view container cover-view
字节一面:TCP 和 UDP 可以使用同一个端口吗?
英特尔两大 FPGA 产品已部署至中国创新中心:性能提高 45%,功耗降低 40%
ggplot2可视化水平箱图并使用fct_reorder排序数据、使用na.rm处理缺失值(reorder boxplot with fct_reorder)、按照箱图的中位数从大到小排序水平箱图
【 8.7 】 source code - card to LCM with GCD 】 【 】
LeetCode_二叉树_中等_515.在每个树行中找最大值
C1. Pokémon Army (easy version)
Nervegrowold: machine advanced learning advice
R语言4.04安装教程
L2-027 名人堂与代金券 (25 分)
laravel database: query builder
2022年11大最佳缺陷管理工具盘点
【入门PCB】立创eda的学习
Appium 自动化测试环境搭建
【LeetCode】试题总结:深度优先搜索 (DFS)
leetcode:294.翻转游戏
垃圾账号不胜其烦,设备指纹快速发现
2022-08-08日报:Kaggle所有竞赛开源方案和Top思路汇总
最稳定的淘宝商品详情接口
开源项目管理解决方案Leantime