#include <stdio.h>
#include <string.h>
int main()
{
int i,j,len,T,n,m,p1,p2,k;
double P1,P2;
int cnt1[105],cnt2[105];
double ans[105];
char st1[105][25],st2[105][15],st3[105];
scanf("%d",&T);
while(T--)
{
scanf("%d %d",&n,&m);
for(i=0;i<n;i++)
{
scanf("%s",st1[i]);
scanf("%s",st2[i]);
scanf("%d",&cnt1[i]);
scanf("%d",&cnt2[i]);
}
p1=0;
for(j=1;j<n;j++)
if(cnt1[p1]<cnt1[j]) p1=j;
P1=300/(double)cnt1[p1];
p2=0;
for(j=1;j<n;j++)
if(cnt2[p2]<cnt2[j]) p2=j;
P2=300/(double)cnt2[p2];
for(i=0;i<n;i++)
{
ans[i]=(double)cnt1[i]*P1*0.3+(double)cnt2[i]*P2*0.7;
}
for(i=0;i<n-1;i++)
{
k=i;
for(j=i+1;j<n;j++)
if(ans[k]<ans[j]) k=j;
if(i!=k)
{
double t=ans[i];
ans[i]=ans[k];
ans[k]=t;
strcpy(st3,st1[i]);
strcpy(st1[i],st1[k]);
strcpy(st1[k],st3);
strcpy(st3,st2[i]);
strcpy(st2[i],st2[k]);
strcpy(st2[k],st3);
}
}
for(i=0;i<n;i++)
{
if(strcmp(st2[i],"female")==0)
{
if(i>m-1)
{
strcpy(st3,st1[i]);
strcpy(st1[i],st1[m-1]);
strcpy(st1[m-1],st3);
}
break;
}
}
printf("The member list of Shandong team is as follows:\n");
for(i=0;i<m;i++)
printf("%s\n",st1[i]);
}
return 0;
#include <string.h>
int main()
{
int i,j,len,T,n,m,p1,p2,k;
double P1,P2;
int cnt1[105],cnt2[105];
double ans[105];
char st1[105][25],st2[105][15],st3[105];
scanf("%d",&T);
while(T--)
{
scanf("%d %d",&n,&m);
for(i=0;i<n;i++)
{
scanf("%s",st1[i]);
scanf("%s",st2[i]);
scanf("%d",&cnt1[i]);
scanf("%d",&cnt2[i]);
}
p1=0;
for(j=1;j<n;j++)
if(cnt1[p1]<cnt1[j]) p1=j;
P1=300/(double)cnt1[p1];
p2=0;
for(j=1;j<n;j++)
if(cnt2[p2]<cnt2[j]) p2=j;
P2=300/(double)cnt2[p2];
for(i=0;i<n;i++)
{
ans[i]=(double)cnt1[i]*P1*0.3+(double)cnt2[i]*P2*0.7;
}
for(i=0;i<n-1;i++)
{
k=i;
for(j=i+1;j<n;j++)
if(ans[k]<ans[j]) k=j;
if(i!=k)
{
double t=ans[i];
ans[i]=ans[k];
ans[k]=t;
strcpy(st3,st1[i]);
strcpy(st1[i],st1[k]);
strcpy(st1[k],st3);
strcpy(st3,st2[i]);
strcpy(st2[i],st2[k]);
strcpy(st2[k],st3);
}
}
for(i=0;i<n;i++)
{
if(strcmp(st2[i],"female")==0)
{
if(i>m-1)
{
strcpy(st3,st1[i]);
strcpy(st1[i],st1[m-1]);
strcpy(st1[m-1],st3);
}
break;
}
}
printf("The member list of Shandong team is as follows:\n");
for(i=0;i<m;i++)
printf("%s\n",st1[i]);
}
return 0;
}
心得:比赛时做的,结果太迟没交成T-T,调试比较麻烦,花了我好长时间= =