One Tower Lake Map (Codevs 1024)

Source: Internet
Author: User

Title Description Description

Komatsu is located in the PK University campus, also known as Yan Garden, is a very beautiful campus. There are Boya tower, peiling, Asia's largest university library, called "a lake map." However, because of the long history of Yan Garden, so many old houses have to be constantly repaired (like the Forbidden City is now in maintenance), which led to some of the road in the garden is forbidden to pass.

Interestingly enough, the shape of the whole Swiftlet garden is a four-sided, north-south orientation, and the architectural pattern of the garden is very regular. You can assume that he was divided into large and small chunks by the n Horizontal and m longitudinal paths. The forbidden roads are just between the two adjacent intersections. Komatsu was wondering how long it would take him to get to the B junction at the library from the a junction where he had his dorm (he could only walk along a passable road and assume that Komatsu walked 1 units in length and needed 1 units of time)? Can you help him? (Do not misunderstand Komatsu so diligent to go to the library to read books, Komatsu to the library is the main reason is that there is the most ppmm place).

Another thing to say is that there are many places in the Swiftlet garden that are lakes. So the area occupied by the lake is also impassable.

Enter a description Input Description

        The first line of the input file contains 4 integers n (1 ≤n ), m (1 ≤m ), t (1 ≤t ), K (1 ≤k 10). Respectively, there are N vertical roads in the garden and the m strip, the roads that are not accessible by the T-Bar, and the K Lakes. The next line has n integers a 1 . An . ai (0 ai 100) indicates the distance from west to East section I from the westernmost end of Yan Yuan; the next line has m integers b 1 : BM . bi (0 ≤bi 100) indicates the distance from south to North section I horizontal road from the southernmost end of the garden; next K line, four integers per line x 1, x 2, y 1, y 2 indicates a lake from the west to the east of the x 1 Road to the x 2 route and the south north of the y 1 Road to the y 2 road. Note that the edge of the lake can be walked, the lake may also overlap, if the two lakes bordering the words, the border of the part can also walk; next T line, 4 integers per line x 1, y 1, x 2, y 2, indicating that the road between the intersection ( x 1, y 1) and ( x 2, y 2) is stationary, you can assume that the two intersections must be adjacent; the last line contains 4 integers x 1, y 1, x 2, y 2, indicates the intersection of Komatsu ( x 1, y 1) and the intersection of the library ( x 2, y 2).

Note: Junction (X,y) represents the intersection of the X- Ray Longitudinal Road from west to east and the y -section of the horizontal road from south to north.

Output description Output Description

The output includes an integer that represents the minimum time it takes for Komatsu to take. Guarantee that there will be no solution to the situation.

Sample input Sample Input

4 4 2 1

0 1 3 4

0 1 3 4

2 4 2 4

2 2 3 2

2 4 3 4

1 3 4 4

Sample output Sample Output

11 (sample error, should be 5)

#include <cstdio>#include<iostream>#include<cstring>#defineM 15#defineINF 9999999using namespacestd;intmap[m*m][m*m],x[m],y[m],cnt,n,m,t,k;voidbuild () {memset (map,0x3f3f3f3f,sizeof(map));  for(intI=1; i<=cnt;i++) Map[i][i]=0;  for(intI=1; i<=n;i++)//map with Map[i][j] as the center       for(intj=1; j<=m;j++)      {          if(i>1) map[(J-1) *n+i][(J-1) *n+i-1]=x[i]-x[i-1];//left        if(j>1) map[(J-1) *n+i][(J-1-1) *n+i]=y[j]-y[j-1];//Upward        if(I<n) map[(J-1) *n+i][(J-1) *n+i+1]=x[i+1]-x[i];//Right        if(J<m) map[(J-1) *n+i][(J-1+1) *n+i]=y[j+1]-Y[J];//downward      }     for(intI=1; i<=t;i++)//to handle the road that can't be gone    {        intX1,y1,x2,y2; scanf ("%d%d%d%d",&x1,&y1,&x2,&y2); map[(Y1-1) *n+x1][(y2-1) *n+x2]=INF; map[(y2-1) *n+x2][(y1-1) *n+x1]=INF; }     for(intL=1; l<=k;l++)//deal with Hu, pay attention to the border.    {        intX1,y1,x2,y2; scanf ("%d%d%d%d",&x1,&x2,&y1,&y2);  for(inti=x1;i<=x2-1; i++)//handles only the right extension in the x direction           for(intj=y1+1; j<=y2-1; j + +) {map[(J-1) *n+i][(J-1) *n+i+1]=INF; map[(J-1) *n+i+1[J-1) *n+i]=INF; }         for(intj=y1;j<=y2-1; j + +)//handles only downward extension in the Y direction           for(inti=x1+1; i<=x2-1; i++) {map[(J-1) *n+i][j*n+i]=INF; Map[j*n+i][(J-1) *n+i]=INF; }     }}voidfloyed () { for(intk=1; k<=cnt;k++)       for(intI=1; i<=cnt;i++)         for(intj=1; j<=cnt;j++)          if(i!=j&&i!=k&&j!=k) Map[i][j]=min (map[i][k]+map[k][j],map[i][j]);}intMain () {scanf ("%d%d%d%d",&n,&m,&t,&k); CNT=n*m;  for(intI=1; i<=n;i++) scanf ("%d",&X[i]);  for(intI=1; i<=m;i++) scanf ("%d",&Y[i]);    Build ();    Floyed (); intX1,y1,x2,y2; scanf ("%d%d%d%d",&x1,&y1,&x2,&y2); printf ("%d", map[(y1-1) *n+x1][(y2-1) *n+x2]);}
View Code

One Tower Lake Map (Codevs 1024)

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.