Noi2010 aviation control

Source: Internet
Author: User
2008: [noi2010] airline control time limit: 10 sec memory limit: 552 MB
Submit: 31 solved: 0
[Submit] [Status] Description during the Expo, the volume of air passenger traffic in Shanghai has exceeded normal times, and the following air control also occurs frequently. Recently, X was delayed at the airport for more than two hours due to air control. In this regard, small X is not satisfied. On the way to Yantai this time, Xiao x unfortunately ran into air control again. So small X began to think about aviation control issues. Assume that there are currently N delayed flights numbered 1 to n. There is only one departure runway at the airport. All flights take off in a certain order (this order is called the Departure sequence ). Define the departure number of a flight as the position of the flight in the departure sequence, that is, the number of flights that take off. There are two types of restrictions on the departure sequence: the first type (the latest departure time limit): the Departure sequence number of a flight numbered I cannot exceed Ki; the second type (the relative Departure Order limit ): there are some restrictions on the relative Departure sequence (a, B), indicating that the departure time of flight A must be earlier than that of flight B, that is, the departure number of flight A must be smaller than that of flight B. The first question for small x thinking is whether a feasible take-off sequence can be computed if the above two types of constraints are given. The second problem is how to find the minimum departure number of each flight in all feasible departure sequences with two types of restrictions. The first line of input contains two positive integers n and M. N indicates the number of flights, and M indicates the number of the second type of restrictions (relative departure order restrictions. The second row contains n positive integers K1, K2 ,..., KN. In the next m row, each row has two positive integers A and B, indicating a pair of relative Departure sequence restrictions (A, B), where 1 ≤ a, B ≤ n, it indicates that flight a must take off before flight B. The first line of output contains N integers, indicating a feasible Departure sequence. Two Adjacent integers are separated by spaces. Input data must have at least one feasible Departure sequence. If there are multiple feasible solutions, output any one. The second row contains N integers T1, T2 ,..., TN, where Ti represents the possible minimum departure number of flight I, and two adjacent integers are separated by spaces. Sample input [Example input 1]
5 5

4 5 2 5 4

1 2

3 2

5 1

3 4

3 1

[Example input 2]
5 0

3 3 3 5 5

Sample output [sample output 1]
3 5 1 4 2

3 4 1 2 1


[Sample output 2]
3 2 1 5 4

1 1 1 4 4

[Example]
In example 1:

The takeoff sequence 3 5 1 4 2 meets all the constraints, and all the takeoff sequences that meet the conditions are:

3 4 5 1 2 3 5 1 4 3 5 1 4 4 2 2 3 5 4 1 2

5 3 1 2 4 5 3 4 4 2 5 3 4 1 2

Because there are two restrictions (5, 1) and (3, 1), Flight 1 can only be arranged after flight 5 and 3, so the first departure time is 3, and other flights are similar.

In Example 2:

Although there are no restrictions on the departure sequence of flights 4 and 5, because flights 1, 2, and 3 must be arranged for the first three flights, 4 and 5 can only be arranged for the first 4th flights.
Hint


[Data Scope]
For 30% data: n ≤ 10;

For 60% data: n ≤ 500;

For 100% data: n ≤ 2,000, m ≤ 10,000.

Source

Day2

Question: It's so disgusting and greedy that I have never done this before ...... Someone's question + code:

A good greedy.

First, let's look at the first question. We need to output a feasible solution.

It only needs to be reversed, that is, if I must be in front of J, then J is connected to I. Then, the initial weight wi of each vertex indicates when to enter at the latest, that is, the latest time Ki, and then run it in topological order, use the wi-1 of each vertex I to update the WJ value of its successor J, (take Min) so as to find the possible latest time of each vertex.

Sort the data in ascending order. (Haha! Ensure that there is a valid sequence ).

The first question is greedy. As for proof, consider that each point must be able to run as late as possible in the case of feasible solutions.

The second question is more difficult than the first question.

For a single vertex I, if we do not consider another vertex, the answer is certainly 1. Now we have to consider which situations will make it have to be pushed back.

1: its precursor must be in the front.

2: The Wj of vertex J which is not arranged before I is smaller than the current time of I.

3: This is a wonderful situation. That is, although J's restrictions are met, it is a tragedy after the point that has not been placed before I.

 

In the first case, BFs is enough.

For the second and third cases, PI indicates the minimum I entry time (initially obtained from BFS) and then scans from small to large.

Case 2: Determine if Wj is <= pi. If yes, ++ pi.

Case 3: Check whether the total number after I and the number before I can meet the J limit. If yes, of course, the number after I will continue to be lost, otherwise, all the items before J are placed before I.

In this way, the problem is solved perfectly.

Code:

 1 const maxn=2000+10;maxm=10000+10; 2 type node=record 3      go,next:longint; 4      end; 5 var head,deg,inp,a,b,q:array[0..maxn] of longint; 6     h,t,i,n,m,x,y:longint; 7     e:array[0..maxm] of node; 8 procedure sort(l,r:longint); 9  var i,j,m,temp:longint;10  begin11  i:=l;j:=r;x:=a[(i+j)>>1];12  repeat13   while b[a[i]]<b[x] do inc(i);14   while b[a[j]]>b[x] do dec(j);15   if i<=j then16    begin17    y:=a[i];a[i]:=a[j];a[j]:=y;18    inc(i);dec(j);19    end;20  until i>j;21  if i<r then sort(i,r);22  if j>l then sort(l,j);23  end;24 procedure init;25  begin26  readln(n,m);27  for i:=1 to n do28   begin29   read(b[i]);30   b[i]:=n-b[i];31   a[i]:=i;32   end;33  sort(1,n);34  for i:=1 to m do35   begin36   readln(y,x);37   e[i].go:=y;inc(inp[y]);e[i].next:=head[x];head[x]:=i;38   end;39  end;40 procedure work(x:longint);41  var i,p,j,u,v:longint;42  begin43  deg:=inp;44  h:=0;t:=0;p:=1;45  for i:=1 to n do46   begin47    while (p<=n) and (b[a[p]]<i) do48     begin49     v:=a[p];50     if (deg[v]=0) and (v<>x) then51      begin52       inc(t);q[t]:=v;53      end;54     inc(p);55     end;56    if h<t then57     begin58     inc(h);59     u:=q[h];60     j:=head[u];61     while j<>0 do62      begin63      v:=e[j].go;64      dec(deg[v]);65      if (deg[v]=0) and (v<>x) and (b[v]<i) then66       begin67       inc(t);q[t]:=v;68       end;69      j:=e[j].next;70      end;71     end72    else exit;73   end;74  end;75 procedure main;76  begin77  work(0);78  for i:=t downto 1 do write(q[i],‘ ‘);writeln;79  for i:=1 to n do80   begin81    work(i);82    write(n-t,‘ ‘);83   end;84  end;85 begin86  assign(input,‘input.txt‘);assign(output,‘output.txt‘);87  reset(input);rewrite(output);88  init;89  main;90  close(input);close(output);91 end.   
View code

 

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.