poj 1042

//枚举+贪心+优先队列
//最有的方案肯定是从起点走到某个点终止,然后在这条路上通过贪心选择最优的选择(每个点应停留的时间)。最后通过比较得出最优的方案
#include <iostream>
#include <queue>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn=26;
int t_spent[maxn],eve[maxn][maxn],cost[maxn],d[maxn];
int n,h;
struct node
{
	int num,begin;
};
node f[maxn];
bool operator<(node a,node b)
{
	if(a.begin==b.begin) return a.num>b.num;
	else return a.begin<b.begin;
}
int solve(int loc,int left)
{
	priority_queue<node> q;
	int i,amount=0;
	for(i=1;i<=loc;i++) q.push(f[i]);
	while(left>=5)
	{
	    if(q.empty()) break;
		node tem=q.top();
        q.pop();
		amount+=tem.begin;
		tem.begin-=d[tem.num];
		if(tem.begin<0) tem.begin=0;
		eve[loc][tem.num]+=5;
		q.push(tem);
		left-=5;
	}
	return amount;
}
int main()
{
	while(cin>>n)
	{
		if(n==0) break;
		scanf("%d",&h);
		memset(eve,0,sizeof(eve));
		memset(cost,0,sizeof(cost));
        int max=-1;
		int i;
		for(i=1;i<=n;i++)
		{
			f[i].num=i;
			cin>>f[i].begin ;
		}
		for(i=1;i<=n;i++) cin>>d[i];
		int tem;
		for(i=2;i<=n;i++)
		{
			scanf("%d",&tem);
			cost[i]=cost[i-1]+tem*5;
		}
		int ou,maxloc;
		for(i=1;i<=n;i++)
		{
			ou=solve(i,h*60-cost[i]);
			if(ou>max)
			{
			  max=ou;
			  maxloc=i;
			}
        }
		for(i=1;i<=n;i++)
		{
		    if(i!=1) printf(", ");
		    printf("%d",eve[maxloc][i]);
		}
		printf("\n");
		printf("Number of fish expected: %d\n\n",max);
	}
	return 0;
}


posted @ 2012-12-21 17:13  LJ_COME!!!!!  阅读(134)  评论(0编辑  收藏  举报