Network Flow topic Exercise Day1

Source: Internet
Author: User

04/16

I've done 8 questions altogether.

First of all, only the maximum flow dinic algorithm and the common cost flow algorithm are mastered by the network flow at present.

Have time to learn about SAP and zkw fee flow (flag early in the front to see the momentum ...

But the algorithm of the network flow personal think is not important, the key to solve problems and the difficulty of thinking are on the map

So this kind of topic often will be the template a dozen, the rest of the code is very short

It's interesting to turn a seemingly unrelated topic into a web stream.

 BZOJ3931 CQOI2015 Network throughput

Title Description
Routing refers to the activity of transmitting information from source address to destination site through computer network, which is also the key point and difficulty in computer network design. A hardware device that implements route forwarding in a network is called a router. In order for the packet to reach the destination fastest, the router needs to select the optimal path forward packet. For example, in the Common routing algorithm OSPF (Open Shortest Path first), routers use the classic Dijkstra algorithm to calculate the shortest path, and then try to forward the packets along the shortest path.
Now, if you know the connection between routers in a computer network, and the maximum throughput of each router (that is, the number of packets that can be forwarded per second), assume that all packets must be forwarded along the shortest path, and try to calculate the maximum throughput of the network from Router 1 to Router n. The time overhead of forwarding and transmission is ignored in the calculation, regardless of the bandwidth limit of the link, that is to say that the packet can be instantaneous over the network. Router 1 to Router n as the starting point and end point, its own throughput is not considered, the network does not exist to connect 1 and n directly linked links.

First run the shortest path according to the topic description, and find out which sides are likely to be transmitted ( possibly more than one side )

About maximum throughput the direct split becomes the edge capacity limit between two points

Note that there is no edge capacity limit for start and end points

And then the direct maximum flow is possible.

BZOJ1001 BEIJING2006 Wolf catches Rabbit

Now the children's favorite "pleasant goat and ash too wolf", saying that the gray wolf catch the sheep, but the rabbit is still more in line, and now the rabbit is more stupid, they only two nest, now you as the Wolf King, facing the following a grid of terrain:

The upper-left corner is (n,m) and the lower-right corner is (n=4,m=5). There are three types of roads 1: (x, y) <==> (x+1,y) 2: (x, y) <==> (x,y+1) 3: (x, y) <==> (x+ 1,Y+1) The weight on the road indicates the maximum number of rabbits that can be passed on this road, and the road is non-direction. The upper-left and lower-right corners of the rabbit's two nests, at the beginning of all the rabbits gathered in the upper left corner of the nest, now they have to go to the lower right solution (n,m) in the nest, The Wolf King began to ambush the rabbits. Of course, for the sake of insurance, if a road up to the number of rabbits passed K, the Wolf King needs to arrange the same number of K wolf, in order to completely block the road, you need to help the Wolf King to arrange an ambush plan, so that the rabbit clean sweep under the premise of the number of wolves involved in the Because the wolf also to find pleasant sheep and sheep trouble.

This problem test instructions let us calculate the minimum cut, but due to a lot of points and edges, running maximum flow will obviously time out

So it leads to a quick approach to the minimum cut of the plan--the shortest way to the dual graph .

We treat each polygon in the plan as a point, and the edges of the two faces as the edges connecting two points, and the side of S and T as the starting point and the other side as the end

So the answer is to seek the shortest way from the beginning to the end of this new map, very good understanding!

But the reason why this problem has been tuned for a long time requires attention.

Generally read the picture when every line read I will write "Readln", but this problem when M=1 is not a picture can read but because n>1 so READLN will still do

This time there is a problem ... After Readln to write carefully

1834: [zjoi2010]network Network expansion Description given a map, each edge has a capacity of C and a cost of expansion W. The expansion fee here refers to the cost of expanding the capacity by 1. 1, in the case of no expansion, the maximum flow of 1 to N, 2, the maximum flow of 1 to n increases the minimum cost of expansion required by K.

  The first question is very clearly the maximum flow, and then the second question must be done with the cost stream

We build an edge with a capacity of C for each side, a cost of 0, and a side with a capacity of + infinity and a cost of W

Then outflow from the source point of the original maximum flow +k flow, do the minimum cost maximum flow can be

1066: [SCOI2007] Lizard

In the grid map of a row C column, there are some highly different pillars, some of which stand on a few lizards, and your task is to get as many lizards as possible to escape the border. The distance of each column in each row is 1, and the lizard's jumping distance is D, that is, the lizard can jump to any one of the columns with a plane distance not exceeding d. The columns are unstable, and each time the lizard jumps, the height of the stone column is reduced by 1 (if it still falls inside the map, the height of the stone column is not changed), and if the column has a height of 1, the lizard disappears after it leaves. Other lizards cannot settle in the future. No two lizards can be found on the same stone column at any one time.

A lizard can be seen as a flow of 1, since the point capacity will be reduced by 1, then split, plus an edge with a height of stone column

The meeting point is all points outside the graph. The maximum flow can be run.

1877: [SDOI2009] Morning run Description Elaxia recently obsessed with karate, he set himself a set of fitness plans, such as push-ups, sit-ups and so on, but so far, He insisted on running only in the morning. Now give a map near the school, which contains n intersections and M streets, Elaxia can only run from one intersection to another, and the streets intersect only at intersections. Elaxia every day from the dormitory run to school, to ensure that the dormitory number 1, the school number is n. Elaxia's morning running plan is carried out by cycle (including several days), because he does not like to follow the repeated route, so in a cycle, the daily morning running route will not intersect (at the crossroads), bedroom and school is not a crossroads. Elaxia stamina is not very good, he hopes to run in a cycle as short as possible, but also want the training cycle to contain as long as possible. In addition to practicing karate, Elaxia other time spent studying and looking for mm above, all he would like to ask you to help him design a suit to meet his requirements of the morning run plan.

This problem description is bare minimum cost maximum flow ... But the starting and ending points cannot be dismantled ...

Note that a detail is when the n=2 , because 1 and N are not limited, so the original program will output + infinity, to the output 1, or set the capacity of the edge to 1

(Of course, the capacity of the side is set to 1 better.) Because in fact we need to set the capacity of the edge to 1, just because after two points are only 1 times, it is definitely omitted

Now that the foundation is gone we need to deal with it, and the contract is ultimately used to compensate for the defects of the program.

1189: [HNOI2007] Emergency evacuation evacuate Description

There's been a fire, and all personnel need emergency evacuation! Suppose each room is a rectangular area of n m. Each lattice, if it is '. ', indicates that this is an empty space; if it is ' X ', then it is a wall, and if it is ' D ', then it is a door where people can withdraw from the room. It is known that the door must be on the boundary of the room and there will be no open space on the border. At first, there was a man in every open space, and every second in the evacuation, everyone could move a grid up and down in four directions, but he could still stand still. After the evacuation began, there was no limit on the number of vacant spaces (i.e. each vacant space could stand at the same time for countless people). However, because the door is very narrow, only one person can move to the door every second, once moved to the door position, it means that he has been safely evacuated. The question now is: If you want all people to evacuate safely, how long will it take? Or it's impossible to tell at all.

This problem was previously done at teacher Zhang, each and every feasible time for each door to the edge, and then the two-figure maximum match, of course, here I use the maximum flow to do

Question asked is the shortest time required, so we two points to the answer, each time to re-build the map

For the problem of network stream re-building, generally note the two points outside the template:

1)Next and link two array clear 0 , otherwise there is a great probability of dying loop

2)e-Clear 0 , of course, this is not easy to forget ...

1305: [Cqoi2009]dance dancing

Description

There were n boys and n Girls at a dance. At the beginning of each song, all the boys and girls fit into the N-dance ballroom. Every boy will not dance with the same girl for two (or more) dance songs. There are some boys and girls who like each other, while others dislike each other (not "one-way Likes"). Each boy is willing to dance with the K-not-like girls at most, and each girl is willing to dance with the K-not-liked boys at most. Given the information that every pair of boys and girls love each other, how many dances can a ball have?

This problem just began to think for a long time did not think out what should be done ...

The map is a type that has not been encountered before ... It was a very interesting question.

Each point I then split two points ix,iy,ix represent point I and like Girl Lian, iy show dot I and don't like girls even

The same is true for girls

Then each point I to IX with a capacity of N-side, to the iy with a capacity of K-side, the same girl

(IX,JX), respectively, (IY,JY), with a capacity of 1

Then S point to each I point to the capacity of the number of dance, J point to T also the capacity of the number of dance edge

When the water from the source point flows to the meeting point, the number of dances can be achieved.

Two-point answer can be

1221: [ HNOI2001] Software development

&NBSP;

description

&NBSP;

A software company is planning an n-day software development plan that requires NI software developers for the first day of the development plan, In order to improve the efficiency of software developers, the company provides software personnel with a lot of services, one of which is to provide each developer a daily piece of disinfection towel, this disinfectant towel used after a day must be disinfected before use. Disinfection methods There are two, a mode of disinfection needs a day, B mode of disinfection needs B Day (B>a), a disinfection method of the cost of each towel FA, B disinfection method of the cost of each towel fb, and buy a new towel for the cost of f (new towel is disinfected, the day can be used); >FA>FB. The company's manager is planning how many new towels to buy each day, how many towels per day, and how many towels are sent per day for the B disinfection of these n days. Of course, company managers want the lowest cost. Your job is to plan how many towels to buy per day, how many towels per day, and how many towels to disinfect for B, so that the company has the lowest total cost of providing towel service in this N-day software development.

&NBSP;

&NBSP;

This question is a classic problem of network flow: Napkin planning Problem

We split each day into two points, each of which represents the day's napkin x and the napkin y used this day.

The source point represents the provider who buys the napkin, first s to X must be connected to the edge

According to the original idea, I want X to connect the x to Y, but it's very unrealistic to find this idea.

  Minimum cost the maximum flow is first guaranteed to be the maximum flow, and this reuse does not increase the flow so it is impossible to appear

This idea reminds us: disinfection also to flow from the source point

So we think of the source point connecting to the Y point, and then from the y point to the X point that can be passed.

The capacity of the source point to the Y point is the number of napkins needed for the day, and this time s we can't interpret it as a napkin provider.

We can interpret it as the X-point corresponding to the Y-point, used up the napkin = The napkin needed for the day = The napkin that can be passed down

Each x point to the T point and the edge of the day that requires a napkin number to limit the flow

Then is the problem of transmission, the first idea is to a+1 days after the days are even edge, that is, n^2 built side?

It's a little bit empty ... After all, the algorithm complexity of network flow is not excellent enough to withstand m=10^6+

And then suddenly found like Noip day1t3 a little similar ... Birds can not fly to lower (or higher?) ) place?

We only need to move up or down in the current state , and the bird's question only needs to be added with an O (1) pass when the current column keeps going down.

This problem is the same, for each Y point only need to the next day of the y point of a side can be

So this problem is almost finished, it feels very ingenious

Summary:

Network flow of the topic are very exercise thinking, may be more suitable for me than some data structure problems

Of course, these maps require very strong observation and modeling capabilities.

Rather than a flash of hope in the examination room

It's better to do some more questions to broaden your mind and accumulate experience

In addition, today tried to finish the day and then write the solution

Personally think not particularly good. Because some of the details of the problem have been forgotten.

Or write a comment next to the code

Of course, the problem of network flow is to write a good job on the spot

Can be sent together at the end of the day, or a part of it can be added

Start correcting tomorrow.

 

Network Flow topic Exercise Day1

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.