"NOI2010" elevation "floor plan min cut"

Source: Internet
Author: User

"Problem description"

yt The city is a well-planned city, and the city is divided by the east-west and north-south Main roads into nxn yt yt cities include (n+1) x (n+1) intersections and 2nx ( n+1) Two-Way Road (abbreviated road), each bidirectional   road connects two adjacent intersections on the main road. For a yt City (n = 2) , the city is divided into 2x2 regions, including 3x3 intersections and 12 two-way road.

Small Z as the mayor of the city, he was based on statistical information on the daily peak of the work of YT city in two directions per road traffic, that is, during the peak period along the way through the road of the number of people. Each intersection has a different altitude value,YT city residents think that climbing is a very tiring thing, every height of the climb up H, you need to consume H 's strength. If it's downhill, you don't need to expend energy. So if the end of a road is at an altitude minus the starting altitude of h ( note H may be a negative number), then the physical strength of a person passing through the road is Max{0, H}(here Max{A, B} represents the larger of a, B two values).

Small Z also measured the intersection of the city's northwest corner at an altitude of 0, the intersection of the southeast corner at an altitude of 1 ( as shown ), but the altitude of the other intersections is unknown. Little Z wants to know in the best case (i.e. you can arbitrarily assume the altitude of the other intersection), the total force and the minimum value of all people climbing during the peak hours of each day.

"input Format"

The first line contains an integer n, meaning as shown above.

Next 4n (n + 1) lines, each line contains a non-negative integer that represents the person traffic information for each direction of each road. Input order:the number of n (n + 1) indicates all people flow from west to east, then N (n + 1) number represents all traffic from north to south,N (n + 1) number represents all people flow from east to west, and finally the number of n (n + 1) indicates all people flow from south to north. For each direction, the input order is given from the north to the south, if the north-south direction is in the same order from west to East ( See sample input ).

"Output format"

Contains only one number, which represents the overall force (i.e., the total strength and minimum) that is consumed by all the people climbing during the peak hours of each day during the most desirable times, rounded to an integer.

"Sample Input"

1

1

2

3

4

5

6

7

8

"Sample Output"

3

"Sample description"

See the sample data.

Ideally a bit of elevation as shown.

"Data Size"

Data for 20% :n≤3;

Data for 50% :n≤15;

Data for 80% :n≤40;

For 100% data:1≤n≤500,0≤ traffic ≤1,000,000 and all traffic is an integer.

"Hint"

Altitude is not necessarily an integer.

"Run Time"

2 seconds.

"Run empty Limit"

512M.

Problem: First, according to the adjustment method can prove that only 0 and 1 of the height, and 0 must be connected together, 11 bound together, and then can think of the minimum cut, because the data range is large, we need to convert to dual graph to find the shortest way. One more problem is that the graph is a graph, and the solution is to turn each side counterclockwise by 90 degrees. (Normal SPFA will time out two points, need to use SLF optimization or heap optimization Dijkstra)

#include <iostream> #include <cstdio> #include <cstring>using namespace Std;int s,t,c,n,point[ 5000001],next[5000001],cnt,dis[5000001],l[50000001];bool f[5000001];struct use{int St,en,val;} b[5000001];void Add (int x,int y,int z) {next[++cnt]=point[x];p oint[x]=cnt;b[cnt].st=x;b[cnt].en=y;b[cnt].val=z;}    int SPFA (int x,int y) {int h,t,u;memset (dis,127/3,sizeof (dis));    Dis[x]=0;h=0;t=1;l[t]=x;f[x]=true;  while (h<t) {u=l[++h];  F[u]=false; for (int i=point[u];i;i=next[i]) if (dis[b[i].en]>dis[u]+b[i].val&&b[i].en!=u) {dis[b[i].en]=dis[u]+b[ I].val;  if (!f[b[i].en]) {f[b[i].en]=true;  if (Dis[b[i].en]<dis[l[h+1]]) l[h--]=b[i].en;   else L[++t]=b[i].en;    }}} if (dis[y]>510000000) dis[y]=0; return dis[y];}   int main () {freopen ("altitude.in", "R", stdin);    Freopen ("Altitude.out", "w", stdout);   scanf ("%d", &n);   s=1;t=n*n+2;  for (int i=1;i<=n+1;i++) for (int j=1;j<=n;j++) {scanf ("%d", &c); if (i==1) Add (j+1,t,c);  if (i==n+1) Add (s,n* (n-1) +j+1,c);   if (i>1&&i<n+1) Add (n (i-1) +j+1,n* (i-2) +j+1,c);  } for (int i=1;i<=n;i++) for (int j=1;j<=n+1;j++) {scanf ("%d", &c), if (j==1) Add (s,n* (i-1) +2,c); if (j==n+1) Add (n (i-1) +n+1,t,c), if (j>1&&j<n+1) Add (n (i-1) +j,n* (i-1) +j+1,c);  }for (int i=1;i<=n+1;i++) for (int j=1;j<=n;j++) {scanf ("%d", &c);  if (i==1) Add (t,j+1,c);  if (i==n+1) Add (n (n-1) +j+1,s,c);   if (i>1&&i<n+1) Add (n (i-2) +j+1,n* (i-1) +j+1,c);  } for (int i=1;i<=n;i++) for (int j=1;j<=n+1;j++) {scanf ("%d", &c), if (j==1) Add (n (i-1) +2,s,c); if (j==n+1) Add (t,n* (i-1) +n+1,c), if (j>1&&j<n+1) Add (n (i-1) +j+1,n* (i-1) +j,c); } COUT&LT;&LT;SPFA (s,t);}



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

"NOI2010" elevation "floor plan min cut"

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.