Bzoj2007 [Noi2010] Altitude

Source: Internet
Author: User

Time limit:20 Sec Memory limit:552 MB submit:2380 solved:1130 Descriptionyt City is a well-planned city, and the city is divided into nxn areas by east-west and north-South Main roads. For simplicity, the YT city can be viewed as a square, and each area can also be viewed as a square. Thus, the YT city includes (n+1) x (n+1) intersection and 2NX (n+1) Two-Way road (abbreviated to the road), each two-way road connecting the main road on the two adjacent intersections. A map of the city of YT (n = 2), the city is divided into 2x2 areas, including 3x3 intersections and 12 bidirectional roads. 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 at H (Note that H is probably negative), then the physical strength of a person passing through this passage is max{0, H} (here Max{a, b} for a, b two values larger). 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. Small Z wants to know in the most ideal case (i.e. you can arbitrarily assume the altitude of the other intersection), every day during the peak hours of all people climbing the total power consumption and the minimum value. The first line of input 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 traffic from west to east, then N (n + 1) number represents all traffic from north to south, the number of n (n + 1) represents all traffic from east to west, and finally the number of n (n + 1) represents all people flow from south to north direction. 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 contains only one number, which indicates 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 in the most ideal situation, rounded to an integer. Sample Input1
1
2
3
4
5
6
7
8Sample Output3

"Sample description"
See the sample data.


Ideally a bit of elevation as shown.
For 100% of data: 1≤n≤500,0≤ traffic ≤1,000,000 and all traffic is an integer.
HINT Source

Brain Tonic can be known that the figure should be divided into only 0 and only 1 of the two Unicom block, so that the 01 junction Edge and minimum.

↑ seems to be the smallest cut.

Looking at the data range, the network stream will definitely be T, so try to convert the minimum cut to the shortest path.

From the northeast side of the map to the southwest (the direction, not necessarily to the corner) to find a path, so that the cost is minimal.

In other blogs to see the magic of the non-explicit construction of the wording, decisively learn to learn.

1 /*by Silvern*/2#include <algorithm>3#include <iostream>4#include <cstring>5#include <cstdio>6#include <cmath>7#include <vector>8#include <queue>9 using namespacestd;Ten Const intmxn=510; One intRead () { A     intx=0, f=1;CharCh=GetChar (); -      while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} -      while(ch>='0'&& ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} the     returnx*F; - } - intN; - intmp[mxn][mxn][4]; + intDIS[MXN][MXN]; - structdist{ +     intX,y,dis; A     BOOL operator< (ConstDist b)Const{ at         returnDis>B.dis; -     } - }; -Priority_queue<dist>Q; - intans=1e9; - voidInsertintXintYintd) { in     if(d<Dis[x][y]) { -dis[x][y]=D; to Q.push ((dist) {x,y,d}); +     } -     if(y==1) Ans=min (ans,d+mp[x][y][1]); the     if(x==n) Ans=min (ans,d+mp[x+1][y][0]); * } $ intDij () {Panax Notoginseng     inti,j; -      for(i=1; i<=n;i++) Insert (1, i,mp[1][i][0]); the      for(j=1; j<=n;j++) Insert (j,n,mp[j][n+1][1]); +      while(!Q.empty ()) { ADist now=q.top (); Q.pop (); the         if(Now.dis>dis[now.x][now.y])Continue; +         intx=now.x;inty=now.y; -         if(x>1){ $Insert (X-1, y,now.dis+mp[now.x][now.y][2]); $         } -         if(y>1){ -Insert (x,y-1, now.dis+mp[now.x][now.y][1]); the         } -         if(x<N) {WuyiInsert (x+1, y,now.dis+mp[now.x+1][now.y][0]); the         } -         if(y<N) { WuInsert (x,y+1, now.dis+mp[now.x][now.y+1][3]); -         } About     } $     return 0; - } - intMain () { -     inti,j; An=read (); +      for(i=1; i<=n+1; i++) the       for(j=1; j<=n;j++) mp[i][j][0]=read ();//from west to east -      for(i=1; i<=n;i++) $       for(j=1; j<=n+1; j + +) mp[i][j][1]=read ();//from north to south the      for(i=1; i<=n+1; i++) the       for(j=1; j<=n;j++) mp[i][j][2]=read ();//from east to west the      for(i=1; i<=n;i++) the       for(j=1; j<=n+1; j + +) mp[i][j][3]=read ();//from south to North -memset (DIS,0x3f,sizeofdis); in Dij (); thecout<<ans<<Endl; the     return 0; About}

Bzoj2007 [Noi2010] Altitude

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.