[Nov 9 greed and induction] simulation competition question

Source: Internet
Author: User

Question A: Number of set Deletions

 

 [Problem description]
A set has the following elements: 1 is a set element; if p is a set element, 2 * p + 1, 4 * P + 5 is also a set element, the minimum k elements in this set are extracted and combined into a multi-digit number in ascending order. Therefore, you must delete the numbers on M digits to maximize the remaining number, program the output of multiple-digit characters before and after deletion.
Note: No data is deleted.
[Input format]
The value of K and m in only one input row is less than or equal to 30000.
[Output format]
The output is two rows. The first row is the number before deletion, and the second row is the number after deletion.
[Example input]
5 4
[Sample output]
137915
95

 

 

Delete Number Problem enhanced edition. The length of the queue is changed because the element is added. Some people may think that, since the queue is determined, it is better to list the queues according to the question and sort the queues and then output the tables? Actually not.

When the number is large, 2 * p + 1, 4 * P + 5 may differ a lot. This interval contains many numbers in the series. If you put all of them into the queue, the total number will be very large and there will be loss.

We use two pointers to record a and B of 2 * A + 1, 4 * B + 5 respectively, and select a small number of Members to join the queue each time, so that the items will not be lost while the monotonicity is ensured.

 

Reference code:

 

Program number; var S, Ans: ansistring; ST: string; C: Char; I, j, k, n, m: longint; A, B: longint; P: array [1 .. 60000] of longint; PO, Len: longint; function min (X, Y: longint): longint; begin if x> Y then exit (y) else exit (X ); end; begin readln (n, m); P [1]: = 1; J: = 1; I: = 1; for K: = 2 to n do // start in a: = P [I] * 2 + 1; B: = P [J] * 4 + 5; if A> B then begin Inc (j); P [k]: = B; end else if a = B then begin Inc (I); Inc (j ); P [k]: = A; end else begin Inc (I); P [k]: = A; end; s: = ''; for I: = 1 to n do begin STR (P [I], St); s: = S + st; end; N: = length (s); PO: = 0; Len: = 0; ans: = ''; while Len <n-M do // delete number begin Inc (LEN); C: = '0'; for I: = PO + 1 to min (m + Len, n) do if s [I]> C then begin C: = s [I]; PO: = I; end; ans: = ans + C; end; writeln (s); writeln (ANS); end.

 

ProblemB: D-Rule Problems 

 

[Problem description]
For any given m (M in n +) and N (N in n +), meet m <n, construct an initial set: P = {x | m ≤ x ≤ n, x ε n +} (m, n ≤ 100 ). A d rule is defined as follows: If k'a' P exists and k'a' N +, K> 1 makes k'a' a' P, change P: P = p-{Y | Y = s 'a, s ε n +}, and the D rule has a score. A program is required to construct the corresponding initial set P for the input M and N values, and accumulate the corresponding score for each application of the d rule for P, evaluate the sequence of the d rule that can obtain the maximum accumulated score, and output the change process of the score and set p each time the D rule is used.
[Input format]
Enter the value of M and N in only one row.
[Output format]
Output the change process of the score and Set P when the D rule is used each time (that is, all the numbers in the changed set, each of which is separated by spaces). Note that D is followed by a space, there is a space after the colon. If it does not change once, 0 is output.
[Example input]
(1)
1 10
(2)
56 57
[Sample output]
(1)
5: 1 2 3 4 6 7 8 9
4: 1 2 3 6 7 9
2: 1 3 7 9
3: 1 7
1:
(2)
0

 

 

Greedy. Policy: Find the number of multiples from m to (m + n) Div 2. The maximum number of objects to be deleted at a time until the objects cannot be deleted.

 

Reference code:

 

program drule;  var    n,m:longint;    a:array[1..100]of longint;    v:array[1..100]of boolean;    i,j,mid,min,k:longint;    f:boolean;  begin    readln(n,m);    mid:=(n+m)div 2;    for i:=n to mid do      for j:=i+1 to m do        if j mod i=0 then inc(a[i]);    fillchar(v,sizeof(v),false);    f:=false;    while true do      begin        j:=0;        min:=100000000;        for i:=mid downto n do          if(a[i]>0)and(not v[i])then            if a[i]<min then              begin                min:=a[i];                j:=i;               end;        if j=0 then break;        f:=true;        for i:=j to m do          if not v[i] then            if i mod j=0 then              begin                v[i]:=true;                for k:=1 to i-1 do                  if i mod k=0 then dec(a[k]);              end;        v[j]:=true;        write(j,' : ');        for i:=n to m do          if not v[i] then            write(i,' ');        writeln;      end;    if not f then writeln('0');  end.

 

ProblemC:  Extreme Value Problems 

Transport: http://www.cnblogs.com/saltless/archive/2010/11/10/1873234.html

 

ProblemD:The treasure map of King Solomon 

 [Problem description]
Baron Henry, Colonel John, and the brave hunters boast man again cracked the button password of King Solomon's treasure cave with the help of the peerless lady frata, and the closed treasure cave door opened slowly. the three treasure hunt heroes can't wait to rush into the cave. they are completely stunned by the countless rare treasures present in front of their eyes. before they go back to the gods, the treasure cave door was automatically closed, and the inner of the treasure cave became dark. they vaguely saw a string of looming numbers at the side of the closed warehouse through the glow of the gem. in the face of sudden changes, Colonel John and batterman's face looked horrified, while baron henry was very confident. it turned out that Baron Henry had been familiar with the treasure hunt secret before he began searching for the treasure. He had mastered the secrets of the loose password of King Solomon's treasure cave. based on the number shown at the edge of the cave door, you can use the mysterious method recorded on the treasure hunt to enter the corresponding password to open the cave door again. how can I obtain the password corresponding to the number displayed at the corner of the cave? This should start with a mobile game that has been popular for centuries.
There are several squares arranged in a row on the board, and one pawn can be placed in each square. the rule of the game of mobile games is that any piece of chess can skip its adjacent pieces along the horizontal direction to enter an empty square and eat the piece that has been skipped. other methods of chess moves are not legal. for the initial layout of several pieces on the board, if there is a legal method to make the final Board only one piece left, this layout is called a perfect layout. in Example 4, the layout of the three pawns is a perfect layout. After two steps are moved, only one pawns are left on the board. the initial layout of the board is represented by the square state from the leftmost part of the Board to the rightmost part. The initial layout shown in Figure 4 is 1101. where 1 indicates the pawn, and 0 indicates space. among all the three pieces on the board, only 1101 and 1011 are the perfect layout, and others are not the perfect layout. for example, if the layout of the board is 111, it cannot be legally moved so that only one piece is left on the board.


If the number displayed at the front of the portal is N, the corresponding exit password is the perfect layout of the game with n chess pieces on the board. design an algorithm for calculating the outgoing password, that is, calculate the perfect layout of the mobile game.
[Input format]
By file treasure. in provides input data. The first line of the file contains a positive integer N, which indicates the number displayed at the front of the websocket. That is, there are n pawns in the initial layout of the board of the game, 0 <n <15536. [output format]
Outputs the calculated outgoing password of the treasure hole, that is, the perfect layout number of n chess pieces on the board to the treasure. Out file.
[Example input]
3
[Sample output]
2

 

Extremely powerful law! You can find the solution of small data by means of manual push or search, and find that the difference between the adjacent items of the series (the difference between the adjacent items *. * |) is ,... This sequence! So easy ~

 

Reference code:

 

program treasure;  var    n,i:integer;    sum:longint;  begin    readln(n);    case n of      1,2:writeln('1');      3:writeln('2');      else begin             sum:=3;             i:=4;             while i<n do               begin                 sum:=sum+3+(i-4) shr 1 shl 2;                 inc(i);               end;             writeln(sum);           end;    end;  end.

 

For details about this simulation competition, please download the ppt from my 115 online storage.

Address: http://u.115.com/file/f9b99a780c <greedy and arithmetic .ppt>

Address: http://www.cnblogs.com/saltless/archive/2010/11/10/1873239.html

(Saltless original, reprinted please indicate the source)

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.