PAT 天梯赛 L2-009. 抢红包 【排序】
2024-09-14 05:42:29
题目链接
https://www.patest.cn/contests/gplt/L2-009
思路
用结构体存储,然后结构体排序 注意一下 个人编号是从 1 开始
计数的
AC代码
#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <numeric>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long LL;
const double PI = 3.14159265358979323846264338327;
const double E = 2.718281828459;
const double eps = 1e-6;
const int MAXN = 0x3f3f3f3f;
const int MINN = 0xc0c0c0c0;
const int maxn = 1e4 + 5;
const int MOD = 1e9 + 7;
struct Node
{
int tot, id;
double sum;
}q[maxn];
bool comp(Node x, Node y)
{
if (x.sum == y.sum)
{
if (x.tot == y.tot)
return x.id < y.id;
return x.tot > y.tot;
}
return x.sum > y.sum;
}
int main()
{
memset(q, 0, sizeof(q));
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++)
q[i].id = i;
for (int i = 0; i < n; i++)
{
int k;
scanf("%d", &k);
int id, num;
for (int j = 0; j < k; j++)
{
scanf("%d%d", &id, &num);
q[id - 1].sum += num;
q[id - 1].tot ++;
q[i].sum -= num;
}
}
sort (q, q + n, comp);
for (int i = 0; i < n; i++)
printf("%d %.2lf\n", q[i].id + 1, q[i].sum / 100);
}
最新文章
- WebView 载入本地的html
- C# 错误代码
- Linux多线程编程阅读链接
- opencv win7 配置
- java类的加载顺序
- mybatis只能模糊查询英文不能查询中文
- Android Ndef Message解析
- kubernetes学习01—kubernetes介绍
- mysql-cluster集群配置
- Nginx.conf配置文件参数说明与优化
- python第三方模块的导入
- 解决kali linux 开启ssh服务后连接不上的问题
- PHP封装类 【 设置分页 】 !!! 可以直接引用 !!! 都有自己理解的注释,挺详细的,有搜到的朋友可以能帮到你们 【 新手一看练两遍就懂 】
- idea 中maven编译速度过慢的问题的解决
- linux:ubuntu安装mysql(二)--推荐
- linux加入windows域
- kubernetes dashboard 安装时出现9090: getsockopt: connection refused错误
- 获取不到offsetHeight问题
- python(33)多进程和多线程的区别
- android--WaveView(波浪形View) 的实现记录
热门文章
- ckeditor编辑时 回车 生成一个段落p、解决首行缩进问题
- Servlet的API(二)
- jQuery的$.fn使用
- MVC| Razor 布局-模板页 | ViewStart.cshtml
- Android模拟屏幕点击input tap替代解决方案
- js 正则匹配 域名【host】
- Python内置函数之str()
- Java中的各种锁--分类总结
- Command &#39;java&#39; not found during running appium
- Collective Mindsets (easy)(逻辑题)