"Bzoj 1295" [SCOI2009] the longest distance

Source: Internet
Author: User

1295: [SCOI2009] Maximum distance time limit: ten Sec Memory Limit: 162 MB
Submit: 945 Solved: 492
[Submit] [Status] [Discuss] Descriptionwindy has a rectangular land, is divided into n*m block 1*1 small lattice. Some grids contain obstructions. If you can walk from lattice A to lattice B, then the distance of two squares is the Euclidean distance from the center of the two lattice. If from lattice a can not go to lattice B, there is no distance. If lattice x and lattice y have common edges, and x and y do not contain obstructions, you can go from X to Y. If the windy can remove the T block obstacle, the maximum distance between all the lattice is obtained. Ensure that there is at least one lattice that does not contain obstructions after removing the T block barrier. Input file maxlength.in The first line contains three integers, N M T. Next there are n lines, each line a string of length m, ' 0 ' for the empty lattice, ' 1 ' indicates that the lattice contains obstructions. The output file Maxlength.out contains a floating-point number that retains 6 decimal places. Sample Input"Input Sample One"
3 3 0
001
001
110


"Input Sample Two"
4 3 0
001
001
011
000


"Input Sample Three"
3 3 1
001
001
001

Sample Output"Output Example One"
1.414214

"Output Example II"
3.605551

"Output Example three"
2.828427
HINT

20% of the data, meet 1 <= n,m <= 0 <= T <= 0.
40% of the data, meet 1 <= n,m <= 0 <= T <= 2.
100% of the data, meet 1 <= n,m <= 0 <= T <= 30.

Source

Day2



spfa+ violence.


For each lattice, use SPFA to preprocess him to any grid at least to remove a few obstacles.


Then the brute force enumeration needs to remove the lattice of the barrier <=t and output the maximum distance.

#include <iostream> #include <cstring> #include <cstdio> #include <cstdlib> #include <cmath > #include <algorithm> #define M 900000+5#define PA pair<int,int> #define MP Make_pair#include <queue > #define INF 0x3f3f3f3fusing namespace std;struct data{double dis;int need;} R[m];char s[100];int f[5][3],tot=0,d[35][35],inq[35][35],n,m,t,a[35][35];queue<pa> q;double dis[35][35][35][ 35];int C (int x,int y) {return (x-1) *m+y;} bool OK (int x,int y) {if (x<1| | y<1| | x>n| | Y&GT;M) return False;return true;} void Spfa (int x,int y) {for (Int. i=1;i<=n;i++) for (int j=1;j<=m;j++) d[i][j]=inf,inq[i][j]=0;d[x][y]=a[x][y]; Q.push (MP (x, y)); Inq[x][y]=1;while (!q.empty ()) {PA p=q.front (); Q.pop (); int xx=p.first,yy=p.second;inq[xx][yy]=0; for (int i=1;i<=4;i++) {int nx=xx+f[i][1],ny=yy+f[i][2];if (OK (nx,ny) &&d[xx][yy]+a[nx][ny]<d[nx][ny]) {d[nx][ny]=d[xx][yy]+a[nx][ny];if (!inq[nx][ny]) Inq[nx][ny]=1,q.push (MP (Nx,ny));}}} for (int i=1;i<=n;i++) for (inT j=1;j<=m;j++) r[++tot].dis=dis[i][j][x][y],r[tot].need=d[i][j];} BOOL CMP (data A,data b) {return a.dis>b.dis;} int main () {f[1][1]=f[2][1]=0,f[1][2]=1,f[2][2]=-1;f[3][2]=f[4][2]=0,f[3][1]=1,f[4][1]=-1;scanf ("%d%d%d", &n, &m,&t), for (int i=1;i<=n;i++) {scanf ("%s", 1+s), and for (int j=1;j<=m;j++) a[i][j]=s[j]-' 0 ';} for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) for (int x=1;x<=n;x++) for (int y=1;y<=m;y++) dis[i][j][x][y]= sqrt (double) (x-i) * (x-i) + (y-j) * (Y-J)); for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) SPFA (i,j); Sort (R+1,r+1+tot , CMP), for (int i=1;i<=tot;i++) if (r[i].need<=t) {printf ("%.6lf\n", R[i].dis); return 0;} return 0;}



"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.