比赛 20110724 评测结果 RRRTTTTTTT
题目名称 准备工作 最终得分 0
用户昵称 PurpleShadow 运行时间 0.000 s
代码语言 C++ 内存使用 0.00 MiB
提交时间 2011-07-24 11:10:30
显示代码纯文本
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N=101,INF=0x3f3f3f3f,K=300;
int Times=100;
int n,p[N],r[N],d[N];
bool init()
{
	scanf("%d",&n);
	if (!n) return 0;
	for (int i=1;i<=n;++i)
		scanf("%d",p+i);
	for (int i=1;i<=n;++i)
		scanf("%d",r+i);
	for (int i=1;i<=n;++i)
		scanf("%d",d+i);
	return 1;
}
int a[N],b[N],c[N];
int Count(int *a)
{
	int i,end=0,s,ans=-INF;
	for (i=1;i<=n;++i)
	{
		s=max(end,r[a[i]]);
		ans=max(ans,s+p[a[i]]-d[a[i]]);
		end=s+p[a[i]];
	}
	return ans;
}
void easy()
{
	int i,ans=0x3f3f3f3f;
	for (i=1;i<=n;++i) a[i]=i;
	do
	{
		ans=min(ans,Count(a));
	}while (next_permutation(a+1,a+n+1));
	printf("%d\n",ans);
}
inline void MYGET(int&a,int &b)
{
	do
		a=rand()%n+1,b=rand()%n+1;
	while (a>=b);
}
void slove()
{
	int st,en,i,ans=0x3f3f3f3f;
	for (i=1;i<=n;++i) a[i]=i;
	while (Times--)
	{
	random_shuffle(a+1,a+n+1);
	int x,y,tmp;
	do
	{
		en=st=Count(a);
		memcpy(c,a,n*4+4);
		for (i=1;i<=K;++i)
		{
			memcpy(b,a,n*4+4);
			MYGET(x,y);
			reverse(b+x,b+y+1);
			if ((tmp=Count(b))<en)
			{
				memcpy(c,b,n*4+4);
				en=tmp;
			}
		}
		if (en<st) memcpy(a,c,n*4+4);else break;
	}while (1);
	ans=min(ans,st);
}
	printf("%d\n",ans);
}
int main()
{
freopen("preparation.in","r",stdin);
freopen("preparatino.out","w",stdout);
	while (init())
		if (n<=11) easy();else 
			slove();
	return 0;
}