当前位置: 首页 > 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;
}

相关文章:

  • 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哨兵)
  • 网站流程图制作软件/个人在线网站推广
  • 公司网站一般去哪里做/关键词优化按天计费
  • 合肥中小企业网站制作/世界足球排名最新
  • 国产前端框架 做网站/站长工具站长之家
  • 东营网站建设制作/网络营销的模式有哪些
  • 如何找有需求做网站的公司/seo实战技术培训