poj 2497 Strategies 模拟

提供一组数据:

输入:

   2

  30 1

  10

  0 1

  10

输出:

 Scenario #1:

Steve wins with 1 solved problems and a score of 10.

Scenario #2:
Steve wins with 0 solved problems and a score of 0.
View Code
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

struct node
{
int s,cnt;
char name[10];
}ans[4];

int ar[30],t,n,ti;

int cmp(int a,int b)
{
return a>b;
}

int cmp1(node a,node b)
{
if (a.cnt>b.cnt)return 1;
if (a.cnt==b.cnt)
{
if(a.s<b.s)return 1;
if(a.s==b.s)return strcmp(a.name,b.name)>0;
}
return 0;
}

void f(int j)
{
int i,sum=0;
for (i=0;i<ti;i++)
{
sum+=ar[i];
if (sum>t)return;
ans[j].cnt=i+1;
ans[j].s+=sum;
}
}

int main()
{
int i,l=1;
scanf("%d",&n);
while(n--)
{
scanf("%d%d",&t,&ti);
memset(ans,0,sizeof(ans));
for (i=0;i<ti;i++)
{
scanf("%d",&ar[i]);
}
strcpy(ans[1].name,"Bill");
f(1);
sort(ar,ar+ti);
strcpy(ans[2].name,"Steve");
f(2);
sort(ar,ar+ti,cmp);
strcpy(ans[3].name,"Linus");
f(3);
sort(ans+1,ans+4,cmp1);
printf("Scenario #%d:\n",l++);
printf("%s wins with %d solved problems and a score of %d.",ans[1].name,ans[1].cnt,ans[1].s);
printf("\n\n");
}
return 0;
}


posted @ 2011-11-26 21:01  104_gogo  阅读(194)  评论(0)    收藏  举报