Bzoj: [Noi2010] Altitude

Source: Internet
Author: User

: [Noi2010] elevation time limit:20 Sec Memory limit:552 MB
submit:2410 solved:1142
[Submit] [Status] [Discuss] 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 [Submit] [Status] [Discuss]

Minimum cut-to-turn dual graph of network flow plan shortest circuit

There is a nature, there must be a set of optimal solution, is some point elevation is 0, the remaining point elevation is 1, and two types of points each form a connected block, that is, the cost of the side is s to t a cutting edge set, the price is the flow and.

In order to prevent tle, it is best to do the shortest path to the dual diagram, note that because there is a forward edge, so the dual graph is also a fixed rule of the forward edge.

1#include <queue>2#include <cstdio>3 4InlineintNextchar (void) {5     Static Const intSiz =1024x768;6     Static CharBuf[siz];7     Static Char*HD = buf +siz;8     Static Char*TL = buf +siz;9     if(HD = =TL)TenFread (HD = buf,1, Siz, stdin); One     return*hd++; A } -  -InlineintNextint (void) { theRegisterintRET =0; -RegisterintNeg =false; -Registerintbit =Nextchar (); -      for(; bit < -; bit =Nextchar ()) +         if(bit = ='-') Neg ^=true; -      for(; bit > -; bit =Nextchar ()) +RET = RET *Ten+ Bit- -; A     returnNeg? -Ret:ret; at } -  - Const intINF =1e9; - Const intSiz =10000005; -  - intN; in ints, t; - intedges; to intHd[siz]; + intTo[siz]; - intNt[siz]; the intVl[siz]; * intDis[siz]; $ Panax NotoginsengInlinevoidAddintUintVintW) { -Nt[edges] =Hd[u]; theTo[edges] =v; +Vl[edges] =W; AHd[u] = edges++; the } +  - structPair { $     intx, y; $Pairvoid) {}; -PairintAintb): - x (a), Y (b) {}; theInline friendBOOL operator< -(ConstPair &a,ConstPair &b) {Wuyi         returna.x >b.x; the     } - }; Wu  -std::p riority_queue<pair>h; About  $InlineintDijkstra (void) { -H.push (pair (dis[s) =0, s)); -      while(!H.empty ()) { -Pair P =h.top (); H.pop (); A         if(DIS[P.Y]! = p.x)Continue; +         if(p.y = = t)returnDIS[P.Y]; the          for(inti = hd[p.y]; ~i; i =Nt[i]) -             if(Dis[to[i] > DIS[P.Y] +Vl[i]) $H.push (Pair (dis[to[i]] = dis[p.y] +Vl[i], to[i]); the     } the     returnDis[t]; the } the  -InlineintPosintXinty) { in     if(x = =0|| y = = n +1)returns; the     if(Y = =0|| x = = n +1)returnT; the     return(X-1) * n +y; About } the  theSigned Main (void) { then =nextint (); +s =0, t = n * n +1; -      for(inti = s; I <= t; ++i) Hd[i] =-1; the      for(inti = s; I <= t; ++i) Dis[i] =inf;Bayi      for(inti =0; I <= N; ++i) the          for(intj =1; J <= N; ++j) theAdd (POS (i, J), POS (i +1, J), Nextint ()); -      for(inti =1; I <= N; ++i) -          for(intj =0; J <= N; ++j) theAdd (POS (i, J +1), POS (i, J), Nextint ()); the      for(inti =0; I <= N; ++i) the          for(intj =1; J <= N; ++j) theAdd (POS (i +1, J), POS (i, J), Nextint ()); -      for(inti =1; I <= N; ++i) the          for(intj =0; J <= N; ++j) theAdd (POS (i, J), POS (i, J +1), Nextint ()); theprintf"%d\n", Dijkstra ());94}

@Author: Yousiki

Bzoj: [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.