Codeforces Memsql.round.1

Source: Internet
Author: User
Tags memsql

A-declined Finalists

Main topic:

There are 1e6 people, serial number from 1 to 1e6, now to invite the first 25 to form a team, but the selected person may be pushed off the invitation, if someone does not go, it is necessary to start from the 26th person to fill up 25 players by serial number. You now know the number of the K-person, to find out at least how many people have pushed off the invitation.

Enter an integer in one line: Represents the known K-person (max. 25).

Enter a single line of K integers: Represents the ordinal number of a known K person.

Output one line of integers: represents at least how many people have pushed out the invitation.

Example input: 25

2 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 22 23 24 25 26 28

5

16 23 8) 15 4

3

14 15 92

Sample output: 3

0

6 7

Problem Solving Ideas:

This problem is more difficult to understand, but the idea is simple: after the sort to see the maximum number.

If it is greater than 25, the result is the difference between the maximum number and 25.

is less than or equal to 25 and results are 0.

A C Code:

1 ImportJava.util.*;2 3  Public classmain{4      Public Static voidMain (string[] args) {5Scanner sc =NewScanner (system.in);6          while(Sc.hasnext ()) {7             intn =sc.nextint ();8             intM[] =New int[n];9              for(inti = 0;i < N;i + +){TenM[i] =sc.nextint (); One             } A Arrays.sort (m); -             if(M[n-1] > 25) {System.out.println (m[n-1]-25);} -             Else{System.out.println ("0");} the         } -     } -}
View Code

B-lazy Security Guard

Main topic:

Solves the minimum perimeter of a graph of n side lengths of square pieces.

Enter an integer on one line: N, which represents you with n small squares.

Output one line of integers: represents the minimum perimeter.

Problem Solving Ideas:

A simple formula, 2 * ((Ceil) (2 * sqrt (n))).

Or, (Ceil) (4 * sqrt (n)) then judge, Odd plus one, even unchanged.

A C Code:

1 ImportJava.util.*;2 3  Public classmain{4      Public Static voidMain (string[] args) {5Scanner sc =NewScanner (system.in);6          while(Sc.hasnext ()) {7             intn =sc.nextint ();8             Doublep = 2 *math.sqrt (n);9             intPP = (int) Math.ceil (p);TenSYSTEM.OUT.PRINTLN (2 *pp); One         } A     } -}
View Code

C-pie Rules

Main topic:

Two persons (A and b) divide n heap Sugar according to the following rules, and two people follow the optimal strategy.

Starting with B, if B takes away the current heap of sugar, then the next pile of rounds to a choose not.

If B does not have this pile of sugar, then give this pile of sugar to a, and continue to choose the next pile.

Until all the sugar is finished. Find out how much sugar two people get.

Enter an integer in one line: N, which represents n heap Candy (n∈[1,50]).

Output a row of n integers: Each integer represents the quantity of a heap of sugars. Sugar is sorted in order from beginning to end.

Output a row of two integers: how much sugar is obtained for A and B, respectively.

Sample input: 3 5

141 592 653 10 21 10 21 10

Sample output: 653 733 31 41

Problem Solving Ideas:

A DP topic. Dp[i] represents the maximum number of apples that a person currently holds the right to assign when assigned to the current heap. Sum[i] Represents the total number of apples allocated for the current heap.

At the beginning, there is always an error ...

Then know that you should reverse the distribution ...

Because of the positive distribution, it is not known who holds the right to assign.

A C Code:

1 ImportJava.util.*;2 3  Public classmain{4      Public Static voidMain (string[] args) {5Scanner sc =NewScanner (system.in);6          while(Sc.hasnext ()) {7             intn =sc.nextint ();8             intPie[] =New int[n + 1];9             intDp[] =New int[n + 1];Ten             intSum[] =New int[n + 1]; One              for(inti = N;i >= 1;i--){ APie[i] =sc.nextint (); -             } -              for(inti = 1;i <= n;i + +){ theSum[i] = sum[i-1] +Pie[i]; -             } -             /* - System.out.print ("sum[] ="); + for (int i = 1;i <= n;i + +) { - System.out.print (Sum[i] + ""); + }system.out.println (); A             */ at              for(inti = 1;i <= n;i + +){ -Dp[i] = Math.max (Dp[i-1],sum[i]-dp[i-1]); -             } -             /* - System.out.print ("dp[] ="); - for (int i = 1;i <= n;i + +) { in System.out.print (Dp[i] + ""); - }system.out.println (); to             */ +System.out.println ((Sum[n]-dp[n]) + "" +dp[n]); -         } the     } *}
View Code

Codeforces Memsql.round.1

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.