TS收好。。。
ffta2吧
全部回复
仅看楼主
level 7
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
bool p[103][103];
long l[103][103];
struct he
{ long x,y,d;
}h[10003];
long hs;
long str[10003][2],fx[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
int up(long i)
{ struct he ls;
while (h[i].d<h[i>>1].d)
{ ls=h[i];
h[i]=h[i>>1];
h[i>>1]=ls;
i>>=1;
}
return 0;
}
int down(long k)
{ long j;
struct he ls;
while ((k<<1)<=hs)
{ j=k<<1;
if (j<hs && h[j].d>h[j+1].d) ++j;
if (h[k].d>h[j].d)
{ ls=h[k];
h[k]=h[j];
h[j]=ls;
}
else break;
k=j;
}
return 0;
}
int main()
{ long i,j,k,m,n,su,hh,tt,o,q,ans=0;
scanf("%ld%ld",&n,&m);
for (i=1;i<=n;++i)
for (j=1;j<=m;++j)
scanf("%ld",&l[i][j]);
for (i=1;i<=n;++i)
{ ++hs;
h[hs].x=i;
h[hs].y=1;
h[hs].d=l[i][1];
up(hs);
++hs;
h[hs].x=i;
h[hs].y=m;
h[hs].d=l[i][m];
up(hs);
}
for (j=2;j<m;++j)
{ ++hs;
h[hs].x=1;
h[hs].y=j;
h[hs].d=l[1][j];
up(hs);
++hs;
h[hs].x=n;
h[hs].y=j;
h[hs].d=l[n][j];
up(hs);
}
memset(p,1,sizeof(p));
for (i=2;i<n;++i)
for (j=2;j<m;++j)
p[i][j]=0;
su=(n-2)*(m-2);
while (su>0)
{ hh=0;
tt=1;
str[1][0]=h[1].x;
str[1][1]=h[1].y;
k=h[1].d;
h[1]=h[hs];
--hs;
down(1);
while (hh<tt)
{ ++hh;
for (i=0;i<4;++i)
{ o=str[hh][0]+fx[i][0];
q=str[hh][1]+fx[i][1];
if (!p[o][q])
{ p[o][q]=1;
--su;
if (l[o][q]<k)
{ ++tt;
str[tt][0]=o;
str[tt][1]=q;
ans+=k-l[o][q];
}
else
{ ++hs;
h[hs].x=o;
h[hs].y=q;
h[hs].d=l[o][q];
up(hs);
}
}
}
}
}
printf("%ld\n",ans);
system("pause");
return 0;
}

2011年06月29日 04点06分 1
level 1
....orz.
2011年06月29日 04点06分 2
level 9
再次表示熊仔的程序看不得。。。。比CLJ好一点
2011年06月29日 05点06分 3
level 9
#include<cstdio>#
include
#include<algorithm>#
include
#include<queue>#
include
#include<ext/hash_map>#
define REP(i,n) for(I i=0;i#define O continue#define U break#define RT returnusing namespace std;typedef int I;const I MD=11192869;I nR,nC,MP[50][3],WT[150],L;I N(){scanf(" ");RT getchar()-'0';}I NE;typedef long long I64;I64 CO(I a[3],I b[4],I r,I c){I64 R=0;REP(i,nC)R=(R<<8)+a[i];REP(i,nC+1)R=(R<<2)+b[i];R=(R<<8)+r;R=(R<<8)+c;RT R;}void AD(I&x,I c){x+=c;if(x>=MD)x-=MD;}typedef bitset<150> BS;struct ST{I64 C;I A;BS V;bool i;void DE(I a[3],I b[4],I&r,I&c){I64 x=C;c=x&255;x>>=8;r=x&255;x>>=8;REP(i,nC+1)b[nC-i]=x&3,x>>=2;REP(i,nC)a[nC-1-i]=x&255,x>>=8;}};const I MS=6e6;ST M[MS],*SK[MS];I top;const I HM=I(1e9)+7;struct HF{I operator()(I64 x)const{RT x%HM;}};__gnu_cxx::hash_mapMO(MS);queueQ;void IQ(I a[3],I b[4],I r,I c,I A,BS&V){I nb[4];memcpy(nb,b,sizeof nb);if(c==0){for(I i=nC;i>=1;--i)nb[i]=nb[i-1];nb[0]=1;}I64 C=CO(a,nb,r,c);ST*s;if(MO.count(C)){s=MO[C];}else{s=SK[--top];*s={C,0,V,0};MO[C]=s;}AD(s->A,A);if(!s->i){s->i=1;Q.push(s);}}bool AR(I r,I c){RT r==0||r==nR-1||c==0||c==nC-1;}I AT(I a,I b){I m=b-a;RT m==1?2:m==0?3:m==-1?0:1;}I main(){cin>>nC>>nR;REP(c,nC)REP(r,nR)MP[r][c]=N();L=nR*nC;REP(i,L)WT[i]=N();NE=L+2;I a[3],b[4];fill(a,a+nC,NE);fill(b,b+nC+1,1);BS V;V.reset();I F=0,T=L-1;top=0;REP(i,MS)SK[top++]=M+i;IQ(a,b,0,0,1,V);I A=0;while(!Q.empty()){ST*s=Q.front();Q.pop();I r,c;s->DE(a,b,r,c);V=s->V;if(r==nR){AD(A,s->A);O;}I nr=r,nc=c+1;if(nc==nC)nr++,nc=0;I p1=b[c],p2=b[c+1];REP(i,L){if(V[i])O;if(WT[i]!=MP[r][c])O;if(i==F&&!AR(r,c))O;if(c>0&&AT(a[c-1],i)!=p1)O;if(AT(a[c],i)!=p2)O;I rp1=2-p1,rp2=2-p2;bool has[3]={};has[rp1]=has[rp2]=1;REP(np1,3){if(np1!=1&&has[np1])O;if(r==nR-1&&np1!=1)O;has[np1]=1;REP(np2,3){if(np2!=1&&has[np2])O;if(c==nC-1&&np2!=1)O;has[np2]=1;do{if(i==F&&(has[0]||!has[2]))U;if(i==T&&(has[2]||!has[0]))U;if(i!=F&&i!=T&&(!has[2]||!has[0]))U;b[c]=np1;b[c+1]=np2;I C=a[c];a[c]=i;V[i]=1;IQ(a,b,nr,nc,s->A,V);V[i]=0;a[c]=C;}while(0);has[np2]=0;}has[np1]=0;}}SK[top++]=s;MO.erase(s->C);}cout<
2011年06月29日 05点06分 4
level 7
orz。。。
百度吃tab。。。
2011年06月29日 06点06分 5
level 8
我擦这坑爹呢
2011年06月29日 09点06分 6
level 7
没错百度坑爹了。。orz
2011年06月29日 09点06分 7
level 9
什么坑爹
2011年06月29日 11点06分 8
level 11
表示没空格很乱码
2011年06月29日 12点06分 9
level 7
是的我也这么觉得度熊太cd了。
2011年06月29日 13点06分 10
level 8
你那个没换行的东西看着蛋疼疼疼疼啊
2011年06月29日 14点06分 11
level 7
那个是丽洁姐姐的神程序。。 一般人看不懂。。 orz 。。[拍砖]
2011年06月29日 14点06分 12
1