Codeforces #275 div2

Source: Internet
Author: User

Link: codeforce #275 div2

A. Counterexample

Given the left and right intervals [l, r], calculate the three numbers a, B, and c in the interval so that a interacts with B,

B and c are mutually qualitative, but a and c are not mutually qualitative. If they do not exist, output-1

Analysis: find the continuous even parity sequence.

# Include <stdio. h> int main () {_ int64 l, r; scanf ("% I64d % I64d", & l, & r); if (l % 2) l ++; if (r-l <2) printf ("-1 \ n"); else printf ("% I64d % I64d % I64d", l, l + 1, l + 2); return 0 ;}

B. Friends and Presents

Construct two sequences. The first sequence must have the number of cnt1 and cannot have a multiple of x,

The second sequence must have the number of cnt2 and cannot have a multiple of y. The two sequences cannot have the same number,

The minimum value of the maximum numbers in the two sequences must be obtained.

Analysis: m = num-num/x, which is the number of numbers from 1 to num that do not contain multiples of x

N = num-num/y, which is the number of numbers from 1 to num that do not contain multiples of x

Num/(x * y) is the number of both x and y.

Therefore, to meet the requirements of m> = cnt1 and n> = cnt2

Because the two sequences cannot have the same number, cnt1 + cnt2 <= num-num/(x * y)

Then, query the minimum value of num in binary mode.

# Include <stdio. h> int main () {_ int64 x, y, cnt1, cnt2, m, n; _ int64 l, r, mid; scanf ("% I64d % I64d % I64d % I64d", & cnt1, & cnt2, & x, & y); l = 1; r = 1e12; while (l <r) {mid = (l + r)/2; m = mid-mid/x; n = mid-mid/y; if (m> = cnt1 & n> = cnt2 & mid-mid/(x * y)> = cnt1 + cnt2) r = mid; else l = mid + 1;} printf ("% I64d \ n", r); return 0 ;}

 

C. Diverse Permutation

Evaluate a series of numbers of n containing 1-n. The number of the absolute values of the two adjacent elements must be k.

Analysis: n numbers have a total of n-1 differences. To ensure that the absolute values of k differences are different,

Then there is the same difference between the n-k-1, you can first output the number of n-k between [1, n-k] in order,

Output the minimum and maximum values of the remaining number in sequence until the number of n is input.

# Include <stdio. h> int main () {int n, k, I, j, num; scanf ("% d", & n, & k); num = n-k-1; for (I = 1; I <= num; I ++) printf ("% d", I); j = n; while (num <n) {printf ("% d", I ++); if (num! = N) printf (""); num ++; if (num = n) break; printf ("% d", j --); if (num! = N) printf (""); num ++;} return 0 ;}


 

Codeforces #275 div2

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.