Codeforces round #262 (Div. 2) Problem Solving report

Source: Internet
Author: User


See: http://robotcator.logdown.com/posts/221514-codeforces-round-262-div-2

A. Vasya and socks http://codeforces.com/contest/460/problem/A

I have n pairs of so. I wear a pair of so every day, and then I threw them away. I bought a pair of new so every M days and asked how many days later I didn't have any so ..
Simple thinking questions: I did not pay attention to training in this area before, and the results have been done for a long time. This kind of questions can be simulated and thought by myself. However, Trick needs to be considered more.
'''C ++
Int main (){
Int n, m;
Long long ans = 0;
Scanf ("% d", & N, & M );
Ans = N/m * m;
Int TMP = N/m;
Int left = TMP + N % m;
While (true ){
Ans + = left/M * m;
TMP = left/m;
Left = TMP + Left % m;
If (left <m) break;
}
Ans + = left;
Printf ("% i64d \ n", ANS );
Return 0;
}
'''
2: B. Little Dima and equation http://codeforces.com/contest/460/problem/ B
Question:
'''Mathjax
Evaluate the solution of the equation x = B * s (x) ^ {A} + c \\
0 \ lt x \ LT 10 ^ {9}, \ 1 \ le A \ le 5, \ 1 \ le B \ le 10000, \-10000 \ le C \ le 10000 \\
S (x) is the sum of X digits.
'''
Question: If simple enumeration X is time-out, we can refer to S (x) from another angle ). This is much simpler. Because we can calculate x according to the right ..
'''C ++

Int get_sum (long x ){
Int ans = 0;
While (x ){
Ans + = x % 10;
X/= 10;
}
Return ans;
}
Int main (){
Int A, B, C;
Scanf ("% d", & A, & B, & C );
Long long ans [maxn];
Int num = 0;
For (INT I = 1; I <= 81; I ++ ){
Long long TMP = 1;
For (Int J = 1; j <= A; j ++) TMP * = I;
Long long temp = B * TMP + C;
If (temp> 1e9) continue;
If (get_sum (temp) = I ){
Ans [num ++] = temp;
}
}
Printf ("% d \ n", num );
If (Num> 0 ){
For (INT I = 0; I <num; I ++)
Printf ("% i64d", ANS [I]);
Printf ("\ n ");
}
Return 0;
}
'''
3: C. Present http://codeforces.com/contest/460/problem/C
There are n flowers, and the initial height is given. Then, the water can be poured m times. W flowers can be Poured Continuously each time. After each watering, the flower will grow to 1 unit. Ask the maximum value of the shortest flower.
Question: At the beginning, you must first select the shortest flower and the adjacent flower for watering. Then a _ (I) to a _ (I + W-1) plus a unit. I didn't expect any good method at the time, so I wanted to use the line segment tree to maintain the minimum value of the interval and find the lower bound of the minimum value each time. Then water all the flowers on the right. At the beginning, I thought about the lower bound for a long time. However, I wrote out the one-dimensional contact information.
'''C ++
Long long a [maxn];
Long long mm [4 * maxn];
Int setv [4 * maxn];

Void build (INT root, int L, int R ){
Int lc = 2 * root, Rc = 2 * root + 1;
If (L <r ){
Int mid = (L + r)/2;
Build (2 * root, L, mid );
Build (2 * root + 1, Mid + 1, R );
Mm [root] = min (Mm [LC], Mm [RC]);
} Else {
Mm [root] = A [l];
}
}

Void Pushdown (INT root, int L, int R ){
Int lc = 2 * root, Rc = 2 * root + 1;
If (setv [root]> 0 ){
Setv [LC] + = setv [root];
Setv [RC] + = setv [root];
Mm [LC] + = setv [root];
Mm [RC] + = setv [root];
Setv [root] = 0;
}
}

Void pushup (INT root, int L, int R ){
Int lc = 2 * root, Rc = 2 * root + 1;
Mm [root] = min (Mm [LC], Mm [RC]);
}

Void modify (INT root, int L, int R, int X, int y, int s ){
If (x <= L & R <= y ){
Mm [root] + = s;
Setv [root] + = s;
} Else {
Pushdown (root, L, R );
Int mid = (L + r)/2;
If (x <= mid) Modify (2 * root, L, mid, X, Y, S );
If (Y> mid) Modify (2 * root + 1, Mid + 1, R, X, Y, S );
Pushup (root, L, R );
}
}

Int Minn;
Void query (INT root, int L, int R, int Z ){
Int lc = 2 * root, Rc = 2 * root + 1, mid = (L + r)/2;
If (L = r ){
If (L <Minn) Minn = L;
} Else {
Pushdown (root, L, R );
If (Mm [LC] <= z) query (LC, L, mid, Z );
Else query (RC, Mid + 1, R, Z );
Pushup (root, L, R );
}
}

Void print (INT root, int L, int R ){
Printf ("% d \ n", root, Mm [root]);
If (L <r ){
Int mid = (L + r)/2;
Print (2 * root, L, mid );
Print (2 * root + 1, Mid + 1, R );
}
}

Int main (){
Int W, n, m;
Scanf ("% d", & N, & M, & W );
For (INT I = 1; I <= N; I ++)
Scanf ("% d", & A [I]);
Memset (setv, 0, sizeof (setv ));
Build (1, 1, n );
// Print (1, 1, n );
For (INT I = 1; I <= m; I ++ ){
Minn = inf;
Query (1, 1, n, Mm [1]);
// Cout <Minn <Endl;
If (n-Minn + 1 <W) Modify (1, 1, N, N-W + 1, n, 1 );
Else modify (1, 1, n, Minn, Minn + W-1, 1 );
}
Printf ("% i64d \ n", Mm [1]);
Return 0;
}
'''
Last night, the last two questions were about 15 minutes away. I didn't come up with any good solutions for the last two questions. Next time, make up.

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.