AtCoder Beginner Contest 156 WriteUp

General comment

As usual, it feels like "complete the ABC problem 3 and get stuck with the D problem for the rest of your life." Looking at the standings, I want to raise the accuracy rate of question D in order to get closer to the target green to blue belt ...

Click here for the contest page:

https://atcoder.jp/contests/abc156

A - Beginner

https://atcoder.jp/contests/abc156/tasks/abc156_a

If $ R_ {in} $ is the internal rating and $ R_ {out} $ is the external rating,

R_{in} = \max( R_{out}+100 \times (10-K), R_{out})

Is.

[N,R]=[int(item)for item in input().split()]
print(max(R, R+100*(10-N)))

https://atcoder.jp/contests/abc156/submissions/11763127


There is also a case where the size of K is usually divided. [^ 1]

[N,R]=[int(item)for item in input().split()]
print(R if N>=10 else R+100*(10-N))

https://atcoder.jp/contests/abc156/submissions/11755645


B - Digits

https://atcoder.jp/contests/abc156/tasks/abc156_b

For example, 100 to 999 are decimal numbers with ** 3 digits **.

That is, the value of $ 10 ^ 2 $ to $ 10 ^ 3-1 $ is ** 3 digits ** in decimal.

Also, values from 1000 to 9999, that is, values from $ 10 ^ 3 $ to $ 10 ^ 4-1 $, have ** 4 digits ** in decimal.

Think in decimal (From now on, add 2 to the lower right of the binary value to clearly indicate that it is a decimal number. For example, the decimal number "5" is the binary number "101", but this is Expressed as $ 101_ {2} $.)

For example, if 6 is expressed in binary, it is $ 110_2 $, which is 3 digits.

In other words, the number between 4 and 7 ($ 100_2 $ to $ 111_2 $) is ** 3 digits ** in binary.

By the way, 4 ~ 7 can also be expressed as $ 2 ^ 2 $ ~ $ 2 ^ 3-1 $.

Also, the number between 8 and 15 ($ 1000_2 $ to $ 1111_2 $) is ** 4 digits ** in binary.

By the way, 8 ~ 15 can also be expressed as $ 2 ^ 3 $ ~ $ 2 ^ 4-1 $.

As you may have noticed [^ 2], this, the upper limit of (lower limit to upper limit), $ 10 ^ 3-1 $, $ 10 ^ 4-1 $, or $ 2 ^ 3-1 $, $ 2 There is a relationship between the exponent of ^ 4-1 $ and the number of decimal digits.

Generally, when the decimal number N is converted to a K-number, between [digits, K, N] $ K ^ {(number of digits) -1} \ leq N \ lt K ^ {(number of digits)} $ The relationship holds.

Taking the logarithm of K for each term $ (Number of digits) -1 \ leq \ log_K (N) \ lt (Number of digits) $ Will be.

(For example, in the case of a sample, (N, K) = (11,2), and $ (number of digits) -1 \ leq \ log_2 (11) = 3.45 ... \ lt (number of digits) $ holds. $ ( Number of digits) 11 is a binary number with 4 digits because there are only 4 integers that can fit in $.)

here, $ (Number of digits) -1 = \ floorloor \ log_K (N) \ rfloor $ Note that the number of digits of N in K-ary is $ (Number of digits) = \ floorloor \ log_K (N) \ rfloor + 1 $

Can be calculated as.

After that, if you put this into the program ...

import math
[N,K]=[int(item)for item in input().split()]
#print(math.log(N,K))
print(math.floor(math.log(N,K))+1)

https://atcoder.jp/contests/abc156/tasks/abc156_b

Consideration

It was $ log_2 (11) = 3.45 ... $. This means that if the concept of "decimal digits" exists, the number of digits required to represent the number 11 in binary is 3.45 ... Of course, there is no concept of decimal numbers in the number of digits (no haze), so at least 4 digits are required to fully represent 11.

There is a "scent" of information entropy in information theory ... but I'm not sure because I'm illiterate. Very disappointing.

C - Rally

https://atcoder.jp/contests/abc156/tasks/abc156_c

Let the coordinates of P obtained in this problem be the same $ P . If you rewrite it again, the desired P is $ P=\min_{P'}\sum^N_{i=1}(X_i-P')^2 $$ Will be.

When $ \ sum ^ N_ {i = 1} (X_i-P') ^ 2 $ is transformed

\sum^N_{i=1}(X_i-P')^2\\
\begin{align}
&=P^2-2X_1P' + X_1^2\\
&+P^2-2X_2P' + X_2^2\\
&\vdots\\
&+P^2-2X_nP' + X_n^2\\
&=nP^2-2(X_1+X_2+...+X_n)P' + (Constant term)\\
&=(P-\frac{X_1+X_2+...+X_n}{n})^2+(Constant term)\\
\end{align}\\

When $ (P- \ frac {X_1 + X_2 + ... + X_n} {n}) ^ 2 \ geq0 $ and $ P = \ frac {X_1 + X_2 + ... + X_n} {n} $ Since $ (P- \ frac {X_1 + X_2 + ... + X_n} {n}) ^ 2 = 0 $, the whole expression is minimized.

(Of course, the same result can be obtained by differentiating with P)

D - Bouquet

I will describe it as soon as it is solved.

[^ 1]: I'm not sure for beginners which implementation is better.

Recommended Posts

AtCoder Beginner Contest 156 WriteUp
AtCoder Beginner Contest 177
AtCoder Beginner Contest 179
AtCoder Beginner Contest 172
AtCoder Beginner Contest 180
AtCoder Beginner Contest 173
Atcoder Beginner Contest 153
AtCoder Beginner Contest 152 Review
AtCoder Beginner Contest 187 Note
AtCoder Beginner Contest 160 Review
AtCoder Beginner Contest 178 Review
AtCoder Beginner Contest 180 Note
AtCoder Beginner Contest 166 Review
AtCoder Beginner Contest 182 Note
AtCoder Beginner Contest 164 Review
AtCoder Beginner Contest 181 Review
AtCoder Beginner Contest 171 Review
AtCoder Beginner Contest 182 Review
AtCoder Beginner Contest 177 Review
AtCoder Beginner Contest 168 Review
AtCoder Beginner Contest 179 Review
Solve AtCoder Beginner Contest 100-102
AtCoder Beginner Contest 167 Memorandum
AtCoder Beginner Contest 172 Review
AtCoder Beginner Contest 183 Note
AtCoder Beginner Contest 176 Review
AtCoder Beginner Contest 184 Note
AtCoder Beginner Contest 175 Review
AtCoder Beginner Contest 174 Review
AtCoder Beginner Contest 153 Review
AtCoder Beginner Contest 156 Review
AtCoder Beginner Contest 161 Review
AtCoder Beginner Contest 170 Review
AtCoder Beginner Contest 165 Review
AtCoder Beginner Contest 173 Review
AtCoder Beginner Contest 188 Note
AtCoder Beginner Contest 155 Review
AtCoder Beginner Contest 162 Review
AtCoder Beginner Contest 181 Participation Report
AtCoder Beginner Contest 175 Virtual entry
AtCoder Beginner Contest 161 Participation Report
AtCoder Beginner Contest 176 Participation Report
AtCoder Beginner Contest 154 Participation Report
AtCoder Beginner Contest # 003 Participation Note
AtCoder Beginner Contest 166 Participation Report
AtCoder Beginner Contest 153 Participation Report
AtCoder Beginner Contest 145 Participation Report
AtCoder Beginner Contest 184 Participation Report
AtCoder Beginner Contest 160 Participation Report
AtCoder Beginner Contest 169 Participation Report
AtCoder Beginner Contest 178 Participation Report
AtCoder Beginner Contest 163 Participation Report
AtCoder Beginner Contest 159 Participation Report
AtCoder Beginner Contest 164 Participation Report
AtCoder Beginner Contest 168 Participation Report
AtCoder Beginner Contest 150 Participation Report
AtCoder Beginner Contest 158 Participation Report
AtCoder Beginner Contest 180 Participation Report
AtCoder Beginner Contest 156 Participation Report
AtCoder Beginner Contest 162 Participation Report
AtCoder Beginner Contest 157 Participation Report