2016多校训练Contest10: 1003 Captain is coding hdu5859

Problem Description
To improve players’ coding skill, FJ collects a variety of problems and order the players to solve them. In order to ensure they can complete the task, FJ divides the problems into two collections and issues a deadline for each collection. He announces that anyone who can’t complete all the problems of any of the two collections before the deadline of it will be downgraded to be an alternative member. 

Now we focus on Captain Chen. His coding skill can be qualified as an integer, which means the level of coding skill. The higher the level is, the faster and the more accurately Captain Chen codes. One has at least Ci level of coding skill is able to solve the ith problem. But after AC it, Captain Chen will get his coding skill increased by Di. Each hour, Captain Chen can either try to solve one problem, or just practice type. If he practices type for one hour, his coding skill will be increased by Z. Please notice that if he AC the same problem twice, the second AC won’t benefit him anymore. And if he chooses to practice or solve the problem, he will practice a whole hour.

Now, he wonders if he could solve all the problems on time. If he could, he also wonders the minimum time needed to accomplish this task.

Can you help Captain Chen?
 

Input
The first line of the input contains a single integer T, indicating there are T cases.

In each case, the first line contains five integers N, the numbers of problems; X, the deadline of problems of collection A; Y, the deadline of problems of collection B; W, the initial coding level of Captain Chen; and Z, which was mentioned above. Next there are N lines, each describing one problem and containing two integers Ci and Di, which are mentioned above. Following the Ci and Di there is a character in each line. The character is either ‘A’ or ‘B’, indicating which collection the problem belongs to.

We guarantee that 0<N<=1000, 0<X, Y<=1000000, 0<Z<=1000, 0<=W<=10^9, 0<=Ci<=10^9, 0<=Di<=1000. Please notice that if the deadline of a problem is X, you can solve the problem in X hours but not X+1 hours.

There are about 1000 cases whose N is no more than 10, about 30 cases whose N is no more than 100, and no more than 5 cases whose N is larger than 100.
 

Output
The output of each case contains a single line. If Captain Chen can solve all the problems before their deadline, this line should be the minimum time needed to do it, measured in hour. Otherwise just print “Poor Captain Chen”.
 

Sample Input
  
  
2 2 10 30 5 1 10 5 A 30 5 B 2 10 20 5 1 10 5 A 30 5 B
 

Sample Output
  
  
22 Poor Captain Chen


首先这题容易想到的是贪心,但是直接贪心的话因为有两个任务所以不好处理

考虑知道时间判定可行性

假设Th完成

不妨设X<=Y,我们可以算出在Xh之内可以做多少件不是A的任务和Th之内练习多少次

那么在前Xh因为一定会做完所有的A任务,所以A的先后次序对最优解无影响,因此能做就优先去做

然后剩下的可以做的不是A任务的部分,我们找可以做的B任务中的最大的和练习一次比较【如果练习次数有剩余】

然后选择收益大的进行即可

那么只需要二分再贪心验证

Y部分的话可以先把剩余的练习提早练了,再按照C从小到大依次把剩下的B任务做完即可

#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<vector>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
struct quest
{
	int c,d;
	bool operator <(quest y) const
	{
		return c<y.c;
	}
}a[1001],b[1001];
bool va[1001],vb[1001];
set< pair<int,int> > S;
int main()
{
//	freopen("1003.in","r",stdin);
//	freopen("1003.ans","w",stdout);
	int T;
	scanf("%d",&T);
	while(T>0)
	{
		T--;
		int n,da,db,w,z;
		scanf("%d%d%d%d%d",&n,&da,&db,&w,&z);
		bool flag=false;
		if(da>db)
		{
			flag=true;
			int t=da;
			da=db;
			db=t;
		}
		int i,j;
		string x;
		int x1,x2;
		int p1=0,p2=0;
		for(i=1;i<=n;i++)
		{
			scanf("%d%d",&x1,&x2);
			cin>>x;
			if(x=="A")
			{
				if(!flag)
				{
					p1++;
					a[p1].c=x1;
					a[p1].d=x2;
				}
				else
				{
					p2++;
					b[p2].c=x1;
					b[p2].d=x2;
				}
			}
			else
			{
				if(!flag)
				{
					p2++;
					b[p2].c=x1;
					b[p2].d=x2;
				}
				else
				{
					p1++;
					a[p1].c=x1;
					a[p1].d=x2;
				}
			}
		}
		sort(a+1,a+1+p1);
		sort(b+1,b+1+p2);
		int l=0,r=db-p1-p2;
		int tw=w;
		while(l<=r)
		{
			memset(vb,false,sizeof(vb));
			set< pair<int,int> >::iterator it=S.begin();
			while(it!=S.end())
				S.erase(it++);
			flag=true;
			w=tw;
			int mid=(l+r)/2;
			int sx1=0,sx2=1;
			int sum1=da-p1,sum2=mid;
			while(sx2<=p2&&b[sx2].c<=w)
			{
				S.insert(make_pair(b[sx2].d,sx2));
				sx2++;
			}
			while(sx1<=p1)
			{
				int maxx=0,maxi=0;
				for(j=sx1+1;j<=p1;j++)
				{
					if(a[j].c<=w)
					{
						sx1++;
						w+=a[j].d;
					}
					else
						break;
				}
				if(sx1>=p1)
					break;
				sum1--;
				if(sum1<0)
				{
					flag=false;
					break;
				}
				set< pair<int,int> >::iterator it;
				while(sx2<=p2&&b[sx2].c<=w)
				{
					S.insert(make_pair(b[sx2].d,sx2));
					sx2++;
				}
				it=S.end();
				if(it!=S.begin())
				{
					it--;
					maxx=(*it).first; 
					maxi=1;
				}
				if(maxi==0)
				{
					sum2--;
					w+=z;
					if(sum2<0)
					{
						flag=false;
						break;
					}
				}
				else
				{
					if(sum2>=1&&maxx<z)
					{
						sum2--;
						w+=z;
					}
					else
					{
						S.erase(it);
						w+=maxx;
					}
				}
			}
			if(!flag)
			{
				l=mid+1;
				continue;
			}
			else
			{
				int dx=0;
				w+=z*sum2;
				set< pair<int,int> >::iterator it=S.begin();
				while(it!=S.end())
				{
					w+=(*it).first;
					it++;
				}
				for(i=sx2;i<=p2;i++)
				{
					if(b[i].c<=w)
						w+=b[i].d; 
					else
					{
						flag=false;
						break;
					}
				}
				if(!flag)
					l=mid+1;
				else
					r=mid-1;
			}
		}
		if(l>db-p1-p2)
			printf("Poor Captain Chen\n");
		else
			printf("%d\n",p1+p2+l);
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值