Codeforces round #193 (first two questions)

Source: Internet
Author: User
A. Down the hatch! Time limit per test

2 seconds

Memory limit per test

256 megabytes

Input

Standard Input

Output

Standard output

Everybody knows that the berland citizens are keen on health, especially students. berland students are so tough that all they drink is orange juice!

Yesterday one student, Vasya and his mates made some barbecue and they drank this healthy drink only. After they ran out of the first barrel of juice, they decided to play a simple game. AllNPeople
Who came to the barbecue sat in a circle (thus each person has ed a unique indexBIFrom
0NCounter-increment 1). The person number 0 started the game (this time it was Vasya). All turns in the game were numbered by integers starting from 1. IfJ-Th
Turn was made by the person with indexBI,
Then this person acted like that:

  1. He pointed at the person with index (BILimit + limit 1)MOD nEither
    With an elbow or with a nod (X mod yIs the remainder after dividingXByY);
  2. IfJLatency ≥ 4 and the players who had turns numberJExecutor-cores 1,JAccept-limit 2,JExecutor-cores 3,
    Made during their turns the same moves as playerBIOn
    The current turn, then he had drunk a glass of juice;
  3. The turn went to Person Number (BILimit + limit 1)MOD n.

The person who was pointed on the last turn did not make any actions.

The problem was, Vasya's drunk too much juice and can't remember the goal of the game. however, Vasya's got the recorded sequence of all the participants 'actions (including himself ). now Vasya wants to find out the maximum amount of juice he cocould drink if
He played optimally well (the other players 'actions do not change). Help him.

You can assume that in any scenario, there is enough juice for everybody.

Input

The first line contains a single integerN(4 cores ≤ CoresNLimit ≤00002000)
-The number of participants in the game. The second line describes the actual game:I-Th character of this line equals 'A ',
If the participant ant who movedI-Th pointed at the next person with his elbow, and 'B ',
If the participant ant pointed with a nod. The game continued for at least 1 and at most 2000 turns.

Output

Print a single integer-the number of glasses of juice Vasya cocould have drunk if he had played optimally well.

Sample test (s) Input
4abbba
Output
1
Input
4abbab
Output
0
Note

In both samples Vasya has got two turns-1 and 5. in the first sample, Vasya cocould have drunk a glass of juice during the previous th turn if he had pointed at the next person with a nod. in this case, the sequence of moves wowould look like "abbbb ". in the second
Sample Vasya wouldn't drink a single glass of juice as the moves stored med during turns 3 and 4 are different.

Question address: #193 A Down the hatch! Give you n people, start to report A or B, and the first person starts to report data in turn. If the first three people report the same letter consecutively, they will have a drink. How many drinks do you have ?.. Only this information is available. As a result, the English language is hard to understand and can only be written for 40 minutes. In the end, WA is also available .. It was too messy.
AC code:
# Include <cstdio> # include <iostream> # include <cstring> # include <string> using namespace STD; int main () {int N, I; char a [2002]; while (CIN> N) {CIN> A; int Len = strlen (a); int res = 0; for (I = N; I <Len; I + = N) {If (A [I-1] = A [I-2]) & (A [I-2] = A [I-3]) // The first three people do the same action, in the N position is not dynamic, then do not need to drink // you start to write is from the n-3 back to consider... Res ++;} cout <res <Endl;} return 0 ;}


B. Maximum absurditytime limit per test

2 seconds

Memory limit per test

256 megabytes

Input

Standard Input

Output

Standard output

Reforms continue entering berland. For example, during yesterday sitting the berland Parliament approved as muchNLaws (each law has been assigned
Unique number from 1N). Today all these laws were put on the table of the president of berland, g.w. boosch, to be signed.

This time mr. boosch plans to sign 2KLaws. He decided to choose exactly two non-Intersecting
Segments of integers from 1NOf LengthKAnd
Sign all laws, whose numbers fall into these segments. More formally, mr. boosch is going to choose two integersA,B(1 digit ≤ DigitALimit ≤ limitBLimit ≤ limitNAccept-Encoding-KLatency + latency 1, latency,BAccept-Encoding-ALimit ≥ limitK) And
Sign all laws with numbers lying in the segments [A;ARegion + RegionKAccept-limit 1] and [B;BRegion + RegionKOrders-orders 1] (borders
Are supported DED ).

As Mr. boosch chooses the laws to sign, he of course considers the public opinion. allberland Public Opinion Study centre (aposc) conducted opinion polls among the citizens, processed the results into a report and gave it to the President. the report contains
The absurdity value for each law, in the public opinion. As Mr. boosch is a real patriot, he is keen on signing the laws with the maximum total absurdity. Help him.

Input

The first line contains two integersNAndK(2 cores ≤ CoresNLimit ≤ limit 2 · 105, 0 rows <limit 2KLimit ≤ limitN)
-The number of laws accepted by the Parliament and the length of one segment in the Law List, correspondingly. The next line containsNIntegersX1, bytes,X2, middle..., middle ,...,XN-
The absurdity of each law (1 limit ≤ limitXILimit ≤ limit 109 ).

Output

Print two integersA,B-The beginning of segments
That mr. boosch shocould choose. That means that the President signs laws with numbers from segments [A;ARegion + RegionKAccept-limit 1] and [B;BRegion + RegionKAccept-limit 1].
If there are multiple solutions, print the one with the minimum numberA. If there still are multiple solutions, print the one with the minimumB.

Sample test (s) Input
5 23 6 1 1 6
Output
1 4
Input
6 21 1 1 1 1 1
Output
1 3
Note

In the first sample mr. boosch signs laws with numbers from segments [1; 2] and [4; 5]. the total absurdity of the signed laws equals 3 Records + limit 6 records + limit 1 records + limit 6 records = Limit 16.

In the second sample mr. boosch signs laws with numbers from segments [1; 2] and [3; 4]. the total absurdity of the signed laws equals 1 minute + minute 1 minute + minute 1 minute + minute 1 minute = minute 4.


Address: #193 B. Maximum absurdity

Give you an N, an array a [n], and a K to find two consecutive intervals that do not want to be handed in so that the left boundary of Two k elements and the two largest intervals is reached. Directly simulate and time out... Then we had to pre-process it again, WA fell out, and finally gave up directly. At that time, we had a headache. You need to use DP to process the data and traverse the data directly. First, find the largest of the first interval, and then push the two intervals and the largest one step by step.
AC code:

# Include <cstdio> # include <iostream> # include <cstring> # include <string> using namespace STD ;__ int64 AA [200005]; // store the initial data _ int64 BB [200005]; // BB [I] indicates the sum of int main () {int N, K, I, p1, P2, PT; while (CIN> N) {CIN> K; for (I = 1; I <= N; I ++) scanf ("% i64d", & aa [I]); memset (BB, 0, sizeof (bb); for (I = 1; I <= K; I ++) bb [1] + = AA [I]; for (I = 2; I <= n-k + 1; I ++) bb [I] = BB [I-1]-aa [I-1] + AA [I + k-1]; P1 = 1; P2 = k + 1; _ int64 ma1 =-1, ma2 =-1; // ma1 is the maximum value of the first range Ma2 is the maximum value of the second range for (I = P2; I <= n-k + 1; I ++) {If (BB [I-K]> ma1) {p1 = I-K; ma1 = BB [I-K];} If (ma1 + BB [I]> Ma2) // use the maximum value of the first interval to maintain the sum of the maximum values of the two intervals {Pt = p1; P2 = I; Ma2 = ma1 + BB [I] ;}} printf ("% d \ n", PT, P2);} return 0 ;}

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.