天天看點

Codeforces Round #443 (Div. 2) A B C

A. Borya’s Diagnosis time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output It seems that Borya is seriously sick. He is going visit n doctors to find out the exact diagnosis. Each of the doctors needs the information about all previous visits, so Borya has to visit them in the prescribed order (i.e. Borya should first visit doctor 1, then doctor 2, then doctor 3 and so on). Borya will get the information about his health from the last doctor. Doctors have a strange working schedule. The doctor i goes to work on the si-th day and works every di day. So, he works on days si, si + di, si + 2di, …. The doctor’s appointment takes quite a long time, so Borya can not see more than one doctor per day. What is the minimum time he needs to visit all doctors? Input First line contains an integer n — number of doctors (1 ≤ n ≤ 1000). Next n lines contain two numbers si and di (1 ≤ si, di ≤ 1000). Output Output a single integer — the minimum day at which Borya can visit the last doctor. Examples input 3 2 2 1 2 output 4 2 10 1 6 5 11 Note In the first sample case, Borya can visit all doctors on days 2, 3 and 4. In the second sample case, Borya can visit all doctors on days 10 and 11.

算出看完所有醫生所花的時間,其實就是算出第幾天看最後一名醫生

B. Table Tennis n people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person from the line, and so on. They play until someone wins k games in a row. This player becomes the winner. For each of the participants, you know the power to play table tennis, and for all players these values are different. In a game the player with greater power always wins. Determine who will be the winner. The first line contains two integers: n and k (2 ≤ n ≤ 500, 2 ≤ k ≤ 1012) — the number of people and the number of wins after which a player leaves, respectively. The second line contains n integers a1, a2, …, an (1 ≤ ai ≤ n) — powers of the player. It’s guaranteed that this line contains a valid permutation, i.e. all ai are distinct. Output a single integer — power of the winner. 4 2 3 1 2 4 6 2 6 5 3 1 2 4 6 2 10000000000 2 1 Games in the second sample: 3 plays with 1. 3 wins. 1 goes to the end of the line. 3 plays with 2. 3 wins. He wins twice in a row. He becomes the winner.

題目說的是赢k場如果這個人輸了就到隊列尾部,但如果一次周遊後沒人赢的話,赢的肯定就是那個power最多的。這題開始不知道哪被hack了。。後來發現,後一個人赢了前邊的沒有算進去一次。。。。

C. Short Program Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well. In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an arbitrary sequence of these operations with arbitrary constants from 0 to 1023. When the program is run, all operations are applied (in the given order) to the argument and in the end the result integer is returned. Petya wrote a program in this language, but it turned out to be too long. Write a program in CALPAS that does the same thing as the Petya’s program, and consists of no more than 5 lines. Your program should return the same integer as Petya’s program for all arguments from 0 to 1023. The first line contains an integer n (1 ≤ n ≤5·105) — the number of lines. Next n lines contain commands. A command consists of a character that represents the operation (“&”, “|” or “^” for AND, OR or XOR respectively), and the constant xi 0 ≤ xi ≤ 1023. Output an integer k (0 ≤ k ≤ 5) — the length of your program. Next k lines must contain commands in the same format as in the input. | 3 ^ 2 | 1 & 1 & 3 & 5 1 ^ 1 ^ 3 Second sample: Let x be an input of the Petya’s program. It’s output is ((x&1)&3)&5 = x&(1&3&5) = x&1. So these two programs always give the same outputs.

繼續閱讀