您的位置:首页 > 其它

CCCC-GPLT L2-009 抢红包 水题

2018-03-23 12:13 211 查看
输入第一行给出一个正整数N(<= 104),即参与发红包和抢红包的总人数,则这些人从1到N编号。随后N行,第i行给出编号为i的人发红包的记录,格式如下:

K N1 P1 … NK PK

其中K(0 <= K <= 20)是发出去的红包个数,Ni是抢到红包的人的编号,Pi(> 0)是其抢到的红包金额(以分为单位)。注意:对于同一个人发出的红包,每人最多只能抢1次,不能重复抢。

一道小模拟.

记得一个人的收获要减去他的支出就好.

/* LittleFall : Hello! */
#include <bits/stdc++.h>
#define ll long long
using namespace std;
inline int read();
inline void write(int x);
const int M = 100016;
struct Item{
int index;
int num;
int amount; //fen
int operator <(const Item &p) const
{
return amount==p.amount?num>p.num:amount>p.amount;
}
}item[M];
int main(void)
{
#ifdef _LITTLEFALL_
freopen("in.txt", "r", stdin);
#endif
//std::cin.sync_with_stdio(false);

int n=read();
for(int i=1;i<=n;i++)
{
item[i].index=i;
int k=read();
for(int j=0;j<k;j++)
{
int ni=read(),pi=read();
item[ni].num++;
item[ni].amount+=pi;
item[i].amount-=pi;
}
}
sort(item+1,item+n+1);
for(int i=1;i<=n;i++)
printf("%d %.2f\n",item[i].index,item[i].amount/100.0);
return 0;
}

inline int read()
{
int x = 0, f = 1;
char ch = getchar();
while(ch < '0' || ch > '9')
{
if(ch == '-')f = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9')
{
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
inline void write(int x)
{
if(x < 0) putchar('-'), x = -x;
if(x > 9) write(x / 10);
putchar(x % 10 + '0');
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: