Wumpus Zoj Month-3890

Source: Internet
Author: User

Wumpus


A wide search problem, the expansion of three states left, turn right, forward;//collect treasures can be judged at the time of advance; The mark of the state can be marked with//a four-dimensional array: coordinates, direction, whether the treasure is all picked up; # include <queue># include < cstdio># include <cstring># include <iostream>using namespace Std;int n,change[30][30],vis[30][30][4][    2],sum,flag;int D[4][2] = {0,-1,-1,0,0,1,1,0};struct point{int m[30][30];    int X,y,f,step,t,flag;        Point operator = (Const point &a) {x = A.x;y = A.y;f = A.f;step = a.step;t = A.t;flag = A.flag;        for (int i = 0;i < n;i++) {for (int j = 0;j < n;j++) M[i][j] = A.m[i][j];    }}}s;void BFs () {queue <Point> q;    S.x = n-1;    S.y = S.step = S.T = s.flag= 0;S.F = 2;    Vis[n-1][0][s.f][0] = 1;    Q.push (s);        while (!q.empty ()) {Point temp = Q.front (); Q.pop ();            for (int i = 0;i < 3;i++) {point e = temp;                if (e.x = = N-1 && E.y = = 0 && e.flag = 1) {e.step++;                flag = 1;   printf ("%d\n", sum*1000-e.step*10);             return;                } if (i = = 0) {e.f = (e.f-1 + 4)% 4,e.step++;                if (!vis[e.x][e.y][e.f][e.flag]) {Vis[e.x][e.y][e.f][e.flag]=1,q.push (e);                }} else if (i = = 1) {e.f = (e.f + 1)% 4,e.step++;                if (!vis[e.x][e.y][e.f][e.flag]) {Vis[e.x][e.y][e.f][e.flag]=1,q.push (e);                }} else if (i = = 2) {e.x + = d[e.f][0],e.y + = d[e.f][1],e.step++;                   if (e.x>=0 && e.x<n && e.y>=0 && e.y<n &&!vis[e.x][e.y][e.f][e.flag]                    && (e.m[e.x][e.y]==0 | | e.m[e.x][e.y]==3)) {Q.push (e);                    Vis[e.x][e.y][e.f][e.flag] = 1;                        if (e.m[e.x][e.y] = = 3) {E.m[e.x][e.y] = 0;                        e.step++,e.t++;    if (e.t = = sum) E.flag = 1;                    Vis[e.x][e.y][e.f][e.flag] = 1;                    Q.push (e);    }}}}}}int main () {int t;    scanf ("%d", &t);        while (t--) {int a,b,c,f = 0;        sum = flag = 0;        memset (change,0,sizeof (change));        memset (vis,0,sizeof (VIS));        scanf ("%d", &n);            while (scanf ("%d%d%d", &a,&b,&c) && A! =-1) {change[b][c] = A;            if (a = = 2 &&!b &&!c) f = 1;        if (a = = 3) sum + +; } for (int i = 0;i < n;i++) {for (int k = 0,j = N-1;k < n && J >= 0;k++,j--) s.m[j][        I] = change[i][k];     } if (f | |!sum) {printf (" -1\n");        Continue        } else BFS ();    if (!flag) printf (" -1\n"); } return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Wumpus Zoj Month-3890

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.