7-1 抢红包 (30分)

输入样例:
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
样例解答:
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
scanf("%d",&n);
double a[n+1]={0};
int b[n+1]={0};
for(int i=1;i<=n;i++){
int t;
scanf("%d",&t);
while(t--){
int x,y;
scanf("%d %d",&x,&y);
a[x]+=y;
b[x]++;
a[i]-=y;
}
}
for(int i=1;i<=n;i++){
int value=-999999,num=0,temp;
for(int j=1;j<=n;j++){
if(a[j]>value){
value=a[j];
num=b[j];
temp=j;
}
if(a[j]==value&&b[j]>num){
num=b[j];
temp=j;
}
}
printf("%d %.2f\n",temp,a[temp]/100);
a[temp]=-999999;
}
}
本文介绍了一个抢红包算法的实现过程,通过输入参与者的数量及各轮抢红包的具体情况,输出每位参与者获得红包金额的排名。该算法使用了C++语言进行实现,并详细展示了如何计算每位参与者最终获得的红包平均值。
5582

被折叠的 条评论
为什么被折叠?



