Bzoj 1295: [SCOI2009] the longest distance

Source: Internet
Author: User

1#include <iostream>2#include <cstdio>3#include <cmath>4#include <cstring>5 using namespacestd;6 intn,m,t;7 Doubleans=0;8 BOOLmp[ to][ to],inq[ to][ to],vis[ to][ to];9 intdis[ to][ to];Ten intdx[4]={1,-1,0,0}; One intdy[4]={0,0,-1,1}; A structdata{ - intx, y; -}q[100000]; the voidGetans (intXinty) - { - for(inti=x;i<=n;i++) - for(intj=1; j<=m;j++) +if(dis[i][j]<=t&& (Y-J) * (y-j) + (x-i) * (x-i) >ans) -ans= (Y-J) * (y-j) + (x-i) * (X-i); + } A voidSearchintXxintyy) at { -intnowx,nowy,i,t=1, w=1, Nx,ny; -q[1].x=xx;q[1].y=yy; -memset (INQ,0,sizeof(INQ)); -memset (DIS,127,sizeof(DIS)); -inq[xx][yy]=1;d is[xx][yy]=Mp[xx][yy]; in while(t<=W) -     { tonowx=q[t].x;nowy=q[t].y; +t++; - for(i=0;i<4; i++) the         { *nx=nowx+dx[i];ny=nowy+Dy[i]; $if(nx>n| | nx<xx| | ny>m| | ny<1)Continue;Panax Notoginseng if(dis[nowx][nowy]+mp[nx][ny]<Dis[nx][ny]) -             { thedis[nx][ny]=dis[nowx][nowy]+Mp[nx][ny]; +if(!Inq[nx][ny]) A                  { theq[++w].x=nx;q[w].y=ny;inq[nx][ny]=1; +                  }       -             } $         } $inq[nowx][nowy]=0; -     } - Getans (xx,yy); the } - intMain ()Wuyi { thescanf"%d%d%d",&n,&m,&T); -Charstr[ +]; Wu for(intI=1; i<=n;i++) -     { Aboutscanf"%s", str); $ for(intj=0; j<m;j++) -mp[i][j+1]=str[j]-'0'; -     } - for(intI=1; i<=n;i++) A for(intj=1; j<=m;j++) + {search (i,j);} theprintf"%.6LF", sqrt (ans)); -return 0; $}

A wide search is centered at each point, the minimum number of obstacles that are saved to each point removed, and the enumeration updates the optimal values.

Bzoj 1295: [SCOI2009] the longest distance

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.