PTA团体程序设计天梯赛-L2-009 抢红包

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#define LL long long
using namespace std;
struct P{
    LL f,v,z;///分别表示编号,红包金额,红包个数
} a[10010];
LL b[10010];///标记,表示每个人只能抢一个红包
LL cmp(P a,P b){
    if(a.v==b.v){
        if(a.z==b.z) return a.f<b.f;
        else return a.z>b.z;
    }
    else return a.v>b.v;
}
int main(){
    LL n,x,y,k;
    while(scanf("%lld",&n)!=EOF){
        memset(a,0,sizeof(a));
        for(int i=1; i<=n; i++){
            a[i].f=i;
            scanf("%lld",&k);
            memset(b,0,sizeof(b));
            for(int j=0; j<k; j++){
                scanf("%lld %lld",&x,&y);
                if(b[x]) continue;
                a[x].v+=y;
                a[x].z++;
                b[x]=1;
                a[i].v-=y;
            }
        }
        sort(a+1,a+n+1,cmp);
        for(int i=1; i<=n; i++)
            printf("%lld %.2lf\n",a[i].f,(1.0*a[i].v)/100);
    }
    return 0;
}
/*#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<set>
#include<iomanip>
using namespace std;
struct node{
	int K;
	double P;
};
struct money{
	int ID;
	node number[10010];
	double moneys;
	double save;
	int nums;
	int count;
	double save_money;
}num[10010];
int vis[10010];
int cmp(money a,money b){
	if(a.save_money==b.save_money){
		if(a.count==b.count){
			  return a.ID<b.ID;
		}else{
			return a.count>b.count;
		}
	}else{
		return a.save_money>b.save_money;
	}
}
int main(){
	int n;
	int k,p,m;
	cin>>n;
	for(int i=1;i<=n;i++){
		num[i].ID=i;
		int sum_money=0;
		memset(vis,0,sizeof(vis));
		cin>>num[i].nums;
		for(int j=1;j<=num[i].nums;j++){
			cin>>num[i].number[j].K>>num[i].number[j].P;
			if(vis[num[i].number[j].K]==0){
				sum_money+=num[i].number[j].P;
				num[num[i].number[j].K].save+=num[i].number[j].P;
				num[num[i].number[j].K].count+=1;
				vis[num[i].number[j].K]=1;
			}
		}
		num[num[i].ID].moneys=sum_money;
	}
	for(int i=1;i<=n;i++){
		num[i].save_money=num[i].save-num[i].moneys;
	}
	sort(num+1,num+n+1,cmp);
	for(int i=1;i<=n;i++){
		cout<<num[i].ID<<setiosflags(ios::fixed)<<setprecision(2)<<" "<<num[i].save_money*1.0/100<<endl;
	}
	return 0;
}
*/
相关推荐
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页