Bzoj 2464: Zhongshan selected [2009] Xiao Ming's game __SPFA

Source: Internet
Author: User
Tags ming

Shortest-Path bare title
I used the SPFA
will not do the league hopeless, like me to supplement the culture class go to it ~
after all, I have a small queue and then the last point Honey WA wa
Listen to the song of the Reol goddess today, the ear pregnancy. Then the ear-digging is bleeding (miscarriage). ). The
asks the storm girl to push me.

#include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #define G GetChar ()
Define ll long #define INF 0x3f3f3f3f using namespace std;
    inline ll read () {ll x=0,f=1;char ch=g; for (;ch< ' 0 ' | |
    Ch> ' 9 '; ch=g) if (ch== '-') f=-1;
    for (; ch>= ' 0 ' &&ch<= ' 9 '; ch=g) x=x*10+ch-' 0 ';
return x*f;
    } inline void out (ll x) {int a[25],t=0;
    if (x<0) Putchar ('-'), x=-x;
    for (; x;x/=10) a[++t]=x%10;
    for (int i=t;i;--i) Putchar (' 0 ' +a[i]);
    if (t==0) Putchar (' 0 ');
Putchar (' \ n '); } struct Re{int v,w,next;}
ED[10000001];
int dis[250001],dui[852369],head[250001],e,n,m;
BOOL pd[250001];
Char ch[501][501];
    inline void ins (int x,int y,int W) {ed[++e]= (re) {y,w,head[x]};head[x]=e;} void Spfa (int x) {int tou=1,wei=1;
    dui[1]=x;pd[x]=1;dis[x]=0;
        for (; tou<=wei;pd[dui[tou++]]=0) {int U=dui[tou];
            for (int i=head[u];i;i=ed[i].next) {int v=ed[i].v;
            if (Ed[i].w+dis[u]<dis[v]) {    Dis[v]=ed[i].w+dis[u];
            if (!pd[v]) dui[++wei]=v,pd[v]=1;
    }} void Clear () {memset (dis,inf,sizeof (dis));
    Memset (head) (head,0,sizeof);
    memset (Pd,0,sizeof (PD));
e=0;
    int main () {//Freopen ("", "R", stdin);//Freopen ("", "w", stdout); for (;;)
        {Clear ();
        N=read (), M=read ();
        if (n==0&&m==0) return 0;
        for (int i=1;i<=n;++i) {scanf ("%s", ch[i]+1); for (int i=1;i<=n;++i) {for (int j=1;j<=m;++j) {if (i-1) Ins (m* (i-1) +j,m* (i-2) +j,c
                H[I][J]!=CH[I-1][J]);
                if (j-1) Ins (m* (i-1) +j,m* (i-1) +j-1,ch[i][j]!=ch[i][j-1]);
                if (j<m) Ins (m* (i-1) +j,m* (i-1) +j+1,ch[i][j]!=ch[i][j+1]);
            if (i<n) Ins (m* (i-1) +j,m*i+j,ch[i][j]!=ch[i+1][j]);
        an int x1=read () +1,y1=read () +1,x2=read () +1,y2=read () +1;
        SPFA ((x1-1) *m+y1);
    Out (dis[(x2-1) *m+y2]);
return 0;
 }

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.