Bzoj thousand plan 230:bzoj3205: [Apio2013] Robot

Source: Internet
Author: User

http://www.lydsy.com/JudgeOnline/problem.php?id=3205

For a day, Lao Tzu finally took it a.

haha haha haha haha haha haha haha haha haha

Because I do not understand the optimization of SPFA and the array cross TAT

┭┮﹏┭┮

The complaint is finished, the puzzle is below (⊙o⊙) ...

N is only 9, very much like a pressure DP

Dp[l][r][x][y] Indicates the minimum number of pushes to synthesize an X-y composite robot at (x, y) position

Its transfer has the aftereffect of

So, Eectilinear.

Transfer of itself: Dp[l][r][x][y]=min{dp[l][k][x][y]+dp[k+1][r][x][y]}

Transfer to each other:

Preprocess the position in the (x, y) position in 4 directions, where it will eventually stay

Can be memory search

Then use SPFA.

Naked SPFA got 65.

Plus SLF optimization, 75.

Plus LLL optimization or 75, but a little bit slower (maybe I won't use tat)

And then changed the double-ended queue or 75.

Finally, I refer to the practice of a big guy:

Double-ended queue optimization is only considering which of the current teams and which is better at the top of the team.

So you can extend this into a monotonous queue, and the root noip2017 earthworms look like

Two queues Q1,q2

Q2 the state of being in the queue in its own transfer, from small to large order.

Then the state shifted out of the Q2, all put into the Q1,

Because the transfer cost is 1,q2 and monotonous, so can guarantee Q1 is also monotonous

Each time comparing Q1 and Q2 's team head, take out the current better state to expand the new state

#include <queue>#include<cstdio>#include<cstring>using namespacestd;#defineN 501typedef pair<int,int>PII;#defineMP (x, y) make_pair (x, y)intT,m,n;CharS[n];intMap[n][n];intdx[4]={-1,0,1,0};intdy[4]={0,1,0,-1};intpos[4][n][n];BOOLv[4][n][n];intdp[Ten][Ten][n][n];inttot,mx;intcnt[n*n*3];p II tmp[n*n],q[n*N];queue<pii>q1,q2;BOOLVis[n][n];inlineint&min (int&x,int&y) {returnX<y?x:y;}BOOLInmap (intXinty) {    if(x<=0|| X>n | | y<=0|| Y&GT;M)return false; if(!map[x][y])return false; return true;}intFindintXintYintd) {    if(Pos[d][x][y])returnPos[d][x][y]; if(!map[x][y])return-2; if(V[d][x][y])return-1; V[d][x][y]=true; intNd=D; if(map[x][y]==-1) nd= (d1+4)%4; if(map[x][y]==-2) nd= (d+1)%4; intnpos=-1; if(!inmap (X+dx[nd],y+dy[nd])) npos=-2; ElseNpos=find (x+dx[nd],y+dy[nd],nd); V[d][x][y]=false; if(npos==-2)returnpos[d][x][y]= (x1) *m+y; Else returnpos[d][x][y]=NPOs;}voidSPFA (intLintR) {       for(intI=0; i<=mx;++i) cnt[i]=0;  for(intI=1; i<=tot;++i) cnt[dp[l][r][tmp[i].first][tmp[i].second]]++;  for(intI=1; i<=mx;++i) cnt[i]+=cnt[i-1];  for(intI=tot;i;--i) q[cnt[dp[l][r][tmp[i].first][tmp[i].second]]--]=Tmp[i];  for(intI=1; i<=tot;++i) Q2.push (Q[i]); intX,y,nx,ny;  while(!q2.empty () | | |Q1.empty ()) {        if(Q1.empty ()) {x=Q2.front (). First; Y=Q2.front (). Second;        Q2.pop (); }        Else if(Q2.empty ()) {x=Q1.front (). First; Y=Q1.front (). Second;            Q1.pop (); Vis[x][y]=false; }        Else if(Dp[l][r][q1.front (). First][q1.front () .second]>Dp[l][r][q2.front (). First][q2.front (). Second]) {x=Q2.front (). First; Y=Q2.front (). Second;        Q2.pop (); }        Else{x=Q1.front (). First; Y=Q1.front (). Second;            Q1.pop (); Vis[x][y]=false; }         for(intI=0;i<4;++i) {if(pos[i][x][y]==-1)Continue; NX= (pos[i][x][y]-1)/m+1; NY=pos[i][x][y]-(nx-1)*m; if(dp[l][r][x][y]+1<Dp[l][r][nx][ny]) {Dp[l][r][nx][ny]=dp[l][r][x][y]+1; if(!vis[nx][ny]) Q1.push (MP (Nx,ny)), vis[nx][ny]=true; }        }    }}intMain () {scanf ("%d%d%d",&t,&m,&N);  for(intI=1; i<=n;++i) {scanf ("%s", s+1);  for(intj=1; j<=m;++j)if(s[j]=='A') map[i][j]=-1; Else if(s[j]=='C') map[i][j]=-2; Else if(s[j]>='1'&& s[j]<='9') map[i][j]=s[j]-'0'; Else if(s[j]=='.') map[i][j]=Ten; }     for(intD=0;d <4;++d) { for(intI=1; i<=n;++i) for(intj=1; j<=m;++j)if(Map[i][j]) find (I,J,D); } memset (DP, the,sizeof(DP)); intoo=dp[0][0][0][0];  for(intI=1; i<=n;++i) for(intj=1; j<=m;++j)if(map[i][j]>=1&& map[i][j]<=9) dp[map[i][j]][map[i][j]][i][j]=0;  for(inti=t;i;--i) for(intj=i;j<=t;++j) {tot=mx=0;  for(intx=1; x<=n;++x) for(inty=1; y<=m;++y) { for(intk=i;k<j;++k) Dp[i][j][x][y]=min (dp[i][j][x][y],dp[i][k][x][y]+dp[k+1][j][x][y]); if(Dp[i][j][x][y]!=oo) tmp[++tot]=mp (x, y), mx=Max (Mx,dp[i][j][x][y]); }            if(TOT) SPFA (I,J); }    intans=Oo;  for(intI=1; i<=n;++i) for(intj=1; j<=m;++j) Ans=min (ans,dp[1][t][i][j]); if(Ans==oo) printf ("-1"); Elseprintf"%d", ans); return 0;}

Bzoj thousand plan 230:bzoj3205: [Apio2013] Robot

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.