151104 系统坑爹计

<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">
</span>
<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">T1最后说</span>

T2

看着像费用流?然后大致写了一下

然后发现点数爆炸只能过暴力。。话说暴力可过为什么费用流?

然后写了搜索,堆优化复杂度

最后T了6个点

下来后:

czh勇士:这题不是做过么

翻了以前的代码,搜索居然过掉了。。于是今天也搜索了。。 40

正解dp。。话说这道题叫做dp真的敢dp?

可以设置第一维当前点,第二维当前状态,维护一下,外面套个二份答案就好啦

T3

好简单的题,结论显然,但是不敢用

写了对拍发现没问题就过掉了 100

回来说T1

这道题要说说坑爹的系统

#ifdef WIN32
	#define lld "%I64d"
#else
	#define lld "%lld"
#endif
#define ll long long
#define ull unsigned long long
#define mod (4294967296ll)

这玩意lemon不认啊!!linux下认I64d!!

然后就坑爹了,,,7个点输出负数

然而我去windows和linux都试过了能用的

说好的在linux下评测呢。。

30->100 考试记得lld啊

这道题有个trick 要开unsignedlonglog或者unsignedint自动取模


//Copyright(c)2015 Liuchenrui
#include <iostream>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <cstdlib>
#define ll long long
#define ull unsigned long long
#define mod (4294967296ull)
using namespace std;
void R(ull &v)
{
	v=0;bool k=true;char c=0;
	while(c>'9' || c<'0'){c=getchar();if(c=='-')k=false,c=getchar();}
	while(c>='0' && c<='9'){v*=10,v+=c-'0';c=getchar();}
	if(!k)v=-v;	
}

ull ans[100];
ull s[100];
ull q[100];
void init()
{
	ans[1]=0;ull now=1;
	for(ull i=2;i<=70;i++)
	{
		if(i>=3)now=now*3ull%mod;
		ans[i]=((ans[i-1]<<1)%mod+(1ull<<(i-2))%mod*now)%mod;
	}
	now=1;
	for(ull i=1;i<=70;i++)
	{
		if(i>=2)now*=3ull;
		ans[i]+=now;
		ans[i]%=mod;
	}
	for(ull i=0;i<=69;i++)ans[i]=ans[i+1];
	for(int i=0;i<=69;i++)s[i]=(ull)ans[i];
	q[1]=1;
	for(int i=2;i<=69;i++)q[i]=q[i-1]*3ull%mod;
}
ull calc(ull x)
{
	ull now=0,ret=0;
	for(ull i=62;i>=0;i--)
	{
		if((1ull<<i)<=x)
		{
			ret+=(((ull)(1ull<<i)%mod*(ull)now)%mod+s[i])%mod;
			now+=q[i+1];now%=mod;
			x-=(1ull<<i);
		}
		if(i==0)break;
	}
	return ret;
}
int main()
{
	freopen("number.in","r",stdin);
	freopen("number.out","w",stdout);
	init();
	ull T;R(T);
	while(T--)
	{
		ull l,r;
		R(l),R(r);
		ull k1=calc(r);
		ull k2=calc(l-1);
		printf("%I64d\n",(k1-k2+mod)%mod);
	}
}


//Copyright(c)2015 Liuchenrui
#include <iostream>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <algorithm>
#define inf 1000000000
using namespace std;
void R(int &v)
{
	v=0;bool k=true;char c=0;
	while(c>'9' || c<'0'){c=getchar();if(c=='-')k=false,c=getchar();}
	while(c>='0' && c<='9'){v*=10,v+=c-'0';c=getchar();}
	if(!k)v=-v;	
}
int f[110][3000],h[110],w[110],c[110],d[110][3000];
int n,i,j,k,m,ans;
bool check(int x)
{
	int cost=0,ret=inf;
	memset(f,63,sizeof f);
	if(h[1]+w[1]>=x)f[1][1<<(k-1)]=c[1];
	if(h[1]>=x)f[1][0]=0;
	d[1][0]=0;d[1][1<<(k-1)]=w[1];
	for(i=2;i<=n;i++)
	{
		for(j=0;j<(1<<k);j++)
		{
			int num=((1<<(k-1))-1)&j;
			cost=min(f[i-1][num<<1],f[i-1][num<<1^1]);
			d[i][j]=d[i-1][num<<1]+(j>>(k-1))*w[i];
			if(h[i]+d[i][j]>=x) f[i][j]=cost+(j>>(k-1))*c[i]; 
		}
	}
	for(i=0;i<(1<<k);i++)ret=min(ret,f[n][i]);
	if(ret<=m)return true;
	return false;
}
int main()
{
	freopen("dp.in","r",stdin);
	R(n),R(m),R(k);<pre name="code" class="cpp">//Copyright(c)2015 Liuchenrui
#include <iostream>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <cstdlib>
#define ll long long
using namespace std;

void R(int &v)
{
	v=0;char c=0;
	while(c>'9' || c<'0'){c=getchar();}
	while(c>='0' && c<='9'){v*=10,v+=c-'0';c=getchar();}
}
int mp[1005][1005];
int fx[1005],fy[1005];
int n,m,q;
int main()
{
	freopen("change.in","r",stdin);
	freopen("change.out","w",stdout);
	R(n),R(m),R(q);
	for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)R(mp[i][j]);
	for(int i=1;i<=1001;i++)fx[i]=fy[i]=i;
	while(q--)
	{
		static char c;while(c=getchar())if(c>='a' && c<='z')break;
		static int x,y;R(x),R(y);
		switch(c)
		{
			case 'c':swap(fy[x],fy[y]);break;
			case 'r':swap(fx[x],fx[y]);break;
			case 'g':cout<<mp[fx[x]][fy[y]]<<endl;
		}
	}
}

int l=0,r=inf;for(i=1;i<=n;i++)R(h[i]),R(w[i]),R(c[i]);while(l<r){int mid=l+r>>1;if(check(mid))l=mid+1;else r=mid;}printf("%d",l-1);return 0;}



你可能感兴趣的:(优化,Win32,dp)