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;
}
}