My tutorial of Codeforces Round #376 (Div.2)

Правка en3, от PengsenMao, 2016-10-17 15:56:40

Something need to say

first of all, this is my first tutorial of one whole round, so there must be some places that i need to improve, if you find bug, just comment it and i will be pleasure to update.

Secondly, this round i got rk 151 in div2. it's too stupid that i came up with a wrong idea which made me waste lots of time, but after the competition, i finish them, it seems the offical tutorial still not okay. Therefore, i published this one.

Third, i wanna say thanks to my friends: samzhang[15120] & quailty[quailty]

A. Night at the Museum

We know if we are posa now and we wanna go to posb, there are two ways.

1.clockwise, which cost |posa - posb|

2.counter-clockwise, which cost 26 - |posa - posb|

just choose the smaller one.

[C++ CODE] [(http://codeforces.net/contest/731/submission/21476722)]

B.Coupons and Discounts

there are two ways to buy pizzas:

1.one day, two pizzas.

2.two day, one pizza each day.

We know it is always better if we can buy exactly ai pizzas in that day

but sometimes ai can't be divided by 2

so we need only buy option#2 : one pizza each day

then we ai - 1 can be divided by 2

but don't forget ai + 1 shoude decrease 1

why only one? beacause the main idea is to make smaller influence

btw, when ai < 0 ( after decreasing ), stop and exit.

[C++ CODE] [(http://codeforces.net/contest/731/submission/21478267)]

C. Socks

consider li, ri as a non-directed edge.

so the question changes into: there are some conected components, one component must be the same color, query the minimum times to modify one vector's color.

it's easy to solve with dsu , first of all, we use dsu to get all conected components. For each conected component, we use the color which has the most frequency to colour this connected component.

so we get an algorithm.

[C++ CODE] [(http://codeforces.net/contest/731/submission/21483617)]

D.80-th Level Archeology

imagine we need to sort an array A

we want Ai < Aj  (j > i), we just need to make Ai < Ai + 1

this problem is the same way, if we want all words are sorted, we just need to compare each pair of adjacent words.

consider about the following two words:AandB(AisinfrontofB)

According to the notice, we know for each i we need Ai ≤ Bi

let x represent the answer, consider two elements, Ai, Bi

if Ai = Bi, skip

if Ai < Bi, absolutely

if Ai > Bi, we also say that

as soon as Ai ≠ Bi is satisfie, we can skip the rest.

how to solve these inequalities? just use Segment_Tree or Bit or Difference

i recommend Difference because C ≤ 106

[C++ CODE] [(http://codeforces.net/contest/731/submission/21517946)]

E. Funny Game

let dp[i] represent the maximum difference when Petya is first,and he got prefix [1, i]

it's easy to see that

s[i] represent

do a change, we have

use suffix maximum array is enough.

consider transform as swaping characters.

[C++ CODE] [(http://codeforces.net/contest/731/submission/21509197)]

F. Video Cards

it is easy to notice that Ai ≤ 2 × 105

so we use an array to count the number of Ai

after that, we suppose Ai is the base

then we know all P that P = k × Ai, find how many times P appears after modifying

it is easy to solve by the array we created.

because of this is harmonic progression, so it is an algorithm.

[C++ CODE][(http://codeforces.net/contest/731/submission/21490349)]

Thanks for reading!

Теги solution, greedy, dp, games

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en6 Английский PengsenMao 2016-10-21 03:29:56 29
en5 Английский PengsenMao 2016-10-17 16:03:21 4 Tiny change: 'o we need only buy optio' -> 'o we need to buy optio'
en4 Английский PengsenMao 2016-10-17 15:58:20 15
en3 Английский PengsenMao 2016-10-17 15:56:40 80
en2 Английский PengsenMao 2016-10-17 15:54:30 163
en1 Английский PengsenMao 2016-10-17 15:52:40 4192 Initial revision (published)