发布网友 发布时间:2023-06-25 19:25
共2个回答
热心网友 时间:2024-10-22 10:44
#include <stdio.h>
热心网友 时间:2024-10-22 10:45
#include<stdio.h>
#include<string.h>
void swap(int *a,int *b)
{
int t ;
t = *a;
*a = *b;
*b = t;
}
int main(void)
{
float aver[10000],total = 0.0;
int pi[10000],gi[10000];
int sum = 0;
int n,m;
int w;
int i,j;
float t;
int max;
scanf("%d%d",&n,&w);
for(i = 0; i < n; i++)
{
scanf("%d%d",&gi[i],&pi[i]);
aver[i] = (1.0*pi[i])/gi[i];
}
for(i = 0; i < n-1; i++)
{
max = i;
for(j = i+1; j < n; j++)
if(aver[max] < aver[j])
max = j;
t = aver[max];
aver[max] = aver[i];
aver[i] = t;
swap(&gi[max],&gi[i]);
swap(&pi[max],&pi[i]);
}
for(i = 0; i< n; i++)
{
sum = sum + gi[i];
if(sum >= 36)
break;
}
if(i == n)
{
for(m = 0; m<n;m++)
total += pi[m];
}
else
{
for(j = 0; j<i;j++)
total += pi[j];
total = total+aver[j]*(36.0-(sum - gi[j]));
}
printf("%.1f",total);
return 0;
}