当前位置: 首页 > news >正文

天梯赛 PTAL2-009 抢红包

很简单的一道模拟题,使用map统计每个用户的钱数和红包数,最后在使用结构体存储,重载小于号,sort排序即可。

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
typedef long long ll;
const int N = 510;
const int mod = 998244353;
struct box{
	int id;
	int money;
	int cnt;
	bool operator<(const box &t) const{
		if(money == t.money && cnt == t.cnt){
			return id < t.id;
		}else if(money == t.money && cnt != t.cnt ){
			return cnt > t.cnt;
		}
		return money > t.money;
	}
};
void solve() {
	int n;
	cin>>n;
	map<int,int> mp;//每个人抢到的红包金额
	map<int,int> cnt;	//红包个数
	for(int i = 1;i <= n ; i++){
		int k;
		cin>>k;
		int sum = 0;
		for(int j = 1 ; j <= k ; j++){
			int x,y;
			cin>>x>>y;
			sum += y;
			mp[x] += y;
			cnt[x]++;
		}
		mp[i] -= sum;
	}
	vector<box> a(n+1);
	for(int i = 1;i <= n ; i++){
		a[i].id = i;
		a[i].money = mp[i];
		a[i].cnt = cnt[i];
	}
	// for(auto it : mp){
		// cout<<it.first<<" "<<it.second<<endl;
	// }
	sort(a.begin()+1,a.end());
	for(int i = 1;i <= n ; i++){
		printf("%d %.2f\n",a[i].id,a[i].money *1.0 / 100);
	}
}
signed main() {
    // ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int tt = 1;
    //    cin >> tt;
    while (tt--) {
        solve();
    }
    return 0;
}


文章转载自:

http://RD5a6Kja.ttnfc.cn
http://y8LvqgPk.ttnfc.cn
http://AoMfYK6w.ttnfc.cn
http://xCoG12iu.ttnfc.cn
http://boxsT1ko.ttnfc.cn
http://YkX6levI.ttnfc.cn
http://pEHQyT36.ttnfc.cn
http://pUHwBeV7.ttnfc.cn
http://9i3ajZ6E.ttnfc.cn
http://LkYvTmYL.ttnfc.cn
http://becVFyhP.ttnfc.cn
http://bfqiJxQW.ttnfc.cn
http://okJ5z2BW.ttnfc.cn
http://mwqLUNvo.ttnfc.cn
http://ob6Zkmuj.ttnfc.cn
http://ftxRHLUa.ttnfc.cn
http://7vmF1xYA.ttnfc.cn
http://Qy2XU4dc.ttnfc.cn
http://EkCpWufr.ttnfc.cn
http://Sbd3v2kC.ttnfc.cn
http://O36Ish3f.ttnfc.cn
http://xgxch9DL.ttnfc.cn
http://rPvkXkVu.ttnfc.cn
http://KLiqfmcP.ttnfc.cn
http://qA0ZsYZN.ttnfc.cn
http://mkBkkxhE.ttnfc.cn
http://Pa3zN8Fv.ttnfc.cn
http://YLFipIi3.ttnfc.cn
http://aCT8igtn.ttnfc.cn
http://pWOQhDLG.ttnfc.cn
http://www.dtcms.com/a/78146.html

相关文章:

  • Hugging Face模型国内镜像HF Mirror下载
  • Python Pyecharts面试题及参考答案
  • OpenHarmony 开源鸿蒙北向开发——linux使用make交叉编译第三方库
  • 计算机四级 - 数据库原理(操作系统部分)- 第3章「进程线程模型」
  • 数据结构-------栈
  • AJAX的理解和原理还有概念
  • AI综合应用及办公应用
  • 工业控制系统中的信号传输格式解析
  • 函数闭包的学习
  • [JavaScript]如何利用作用域块避免闭包内存泄漏?
  • Moonlight-16B-A3B: 变革性的高效大语言模型,凭借Muon优化器打破训练效率极限
  • DNS缓存使用中有什么问题?DNS缓存有哪些作用?
  • 蓝桥杯day2:解码异或 后的数组
  • test_cases测试用例层/test_1_login
  • ubuntu中的环境变量文件 bashrc、profile、environment简要总结
  • 【Java篇】一气化三清:类的实例化与封装的智慧之道
  • 口袋书签功能上新,免费使用
  • 网络华为HCIA+HCIP AAA原理与配置
  • 8.4《同一直线上二力的合成》
  • Linux下Redis哨兵集群模式搭建(1主2从+3哨兵)
  • Python实现WYY音乐下载
  • 机器学习快速入门教程
  • 设计模式工厂模式和单例模式结合
  • QwQ-32B 模型结构
  • 杰理科技JL703N双模蓝牙芯片—云信
  • 在node.js环境中使用web服务器http-server运行html静态文件
  • pytorch 笔记:张量索引的维度扩展规则
  • 【Linux】进程概念和进程状态
  • 单片机写的小液晶屏驱动+汉字滚屏
  • 天梯赛 L2-008 最长对称子串 (天梯赛常用string函数)