7-1抢红包

7-1 抢红包
分数 35
作者 陈越
单位 浙江大学
没有人没抢过红包吧…… 这里给出N个人之间互相发红包、抢红包的记录,请你统计一下他们抢红包的收获。

输入格式:
输入第一行给出一个正整数N(≤10
4
),即参与发红包和抢红包的总人数,则这些人从1到N编号。随后N行,第i行给出编号为i的人发红包的记录,格式如下:

KN
1

P
1

⋯N
K

P
K

其中K(0≤K≤20)是发出去的红包个数,N
i

是抢到红包的人的编号,P
i

(>0)是其抢到的红包金额(以分为单位)。注意:对于同一个人发出的红包,每人最多只能抢1次,不能重复抢。

输出格式:
按照收入金额从高到低的递减顺序输出每个人的编号和收入金额(以元为单位,输出小数点后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

//没有人没抢过红包吧…… 这里给出N个人之间互相发红包、抢红包的记录,请你统计一下他们抢红包的收获。
// 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
// 其中K(0≤K≤20)是发出去的红包个数,Ni是抢到红包的人的编号,Pi(>0)是其抢到的红包金额(以分为单位)。
// 注意:对于同一个人发出的红包,每人最多只能抢1次,不能重复抢。


//====================
//按照收入金额从高到低的递减顺序输出每个人的编号和收入金额(以元为单位,输出小数点后2位)。
// 每个人的信息占一行,两数字间有1个空格。
// 如果收入金额有并列,则按抢到红包的个数递减输出;如果还有并列,则按个人编号递增输出。
// 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

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;


struct Person{
    int id;
    //int expense;//支出//分
    //int income;//收入//分
    int sum;
    int amount;
}p[10010];

bool cmp(Person a,Person b){
    if(a.sum!=b.sum)return a.sum>b.sum;
    else if(a.amount!=b.amount)return a.amount>b.amount;
    else return a.id<b.id;
}

int main()
{
    int n;
    cin>>n;
    
    for(int i=1;i<=n;i++){
        p[i].id=i;
        p[i].amount=0;
        p[i].sum=0;
    }
    
    getchar();
    for(int i=1;i<=n;i++){
        int num;
        cin>>num;
        for(int j=0;j<num;j++){
            int id,income;
            scanf(" %d %d",&id,&income);
            p[id].id=id;
            p[id].sum+=income;
            p[id].amount++;
            p[i].sum-=income;
            getchar();
        }
    }
    sort(p+1,p+n+1,cmp);
    
    for(int i=1;i<=n;i++){
        printf("%d %.2f\n",p[i].id,double(p[i].sum/100.00));
    }
    return 0;
}
#include <iostream>
#include <stack>
#include <vector>
#include <algorithm>
using namespace std;
struct Person{
    int order;
    int income;
    int count;
};
// bool cmp(Person p1, Person p2) {
//     if(p1.income != p2.income) {
//         return p1.income > p2.income;
//     }else if(p1.count != p2.count) {
//         return p1.count > p2.count;
//     }else{
//         return p1.order < p2.order;
//     }
// }
bool cmp(Person a,Person b){
    if(a.income!=b.income)return a.income>b.income;
    else if(a.count!=b.count)return a.count>b.count;
    else return a.order<b.order;
}
int main()
{
//    vector<Person> persons;
    Person persons[10005];
    int N;
    cin >> N;
    for(int i = 1; i <= N; i++) {
        persons[i].order = i;
        persons[i].count = 0;
        persons[i].income = 0;
    }
    for(int i = 1; i <= N; i++) {
        int K;
        cin >> K;
        for(int j = 0; j < K; j++) {
            int n, P;
            cin >> n >> P;
//             persons[n].order = n;
            persons[n].income += P;
            persons[n].count += 1;
            persons[i].income -= P;
        }
    }
    sort(persons + 1, persons + N + 1, cmp);
    for(int i = 1; i <= N; i++) {
//         cout << persons[i].order << " " << double(persons[i].income / 100.00) << endl;
        printf("%d %.2f\n",persons[i].order,double(persons[i].income/100.00));
    }
    return 0;
}
posted @ 2023-03-01 20:40  Travelever  阅读(51)  评论(0)    收藏  举报