Codeforces Round #262 (Div. 2 ),

Source: Internet
Author: User

Codeforces Round #262 (Div. 2 ),
Codeforces Round #262 (Div. 2)

A: You can directly simulate the problem.

B: Since the size of s (x) is as large as 1e9, the number and the maximum value are 81. In this way, if we enumerate s (x), we only need to enumerate 1 to 81, then, after calculating the x value, determine whether the x value is correct. If yes, add the answer.

C: two points of height. Then, when you judge it, you need to water it at the wrong position and push it from left to right.

D: constructor. If k> = 5, you can directly put the even, odd, even, and odd numbers. Because the even and even numbers + 1 are different or must be 1, so let's put the four XOR values to the smallest zero, and then k = 1, 2, 4 can be identified. The key lies in how to construct k = 3, in fact, as long as the highest bit of l is found, write down this number as p. If 3 p does not exceed r, it can be constructed. You can select l, l + p, and 3 p to construct 0, if not, select two exclusive or sum. 1 is the best choice.

Code:

A:

#include <cstdio>#include <cstring>#include <cstdlib>int n, m;int main() {int ans = 0;scanf("%d%d", &n, &m);while (n >= m) {ans += n - n % m;int num = n / m;n = n % m + num; } printf("%d\n", ans + n); return 0;}

B:

#include <cstdio>#include <cstring>#include <cstdlib>#include <algorithm>#include <set>#include <iostream>using namespace std;typedef long long ll;ll a, b, c;set<ll> ans;ll out[105], on = 0;ll pow1(ll x, ll k) {ll ans = 1;for (ll i = 0; i < k; i++)ans *= x;return ans;}bool judge(ll num, ll x) {ll sum = 0; while (num) {sum += num % 10;num /= 10; } return sum == x;}int main() {scanf("%lld%lld%lld", &a, &b, &c);for (ll i = 0; i <= 81; i++) { ll tmp = b * pow1(i, a) + c; if (tmp > 0LL && tmp < 1000000000LL && judge(tmp, i)) ans.insert(tmp); } for (set<ll>::iterator it = ans.begin(); it != ans.end(); it++) out[on++] = *it; printf("%lld\n", on);for (ll i = 0; i < on - 1; i++)printf("%lld ", out[i]);if (on)printf("%lld\n", out[on - 1]);return 0;}

C:

#include <cstdio>#include <cstring>#include <cstdlib>#include <algorithm>using namespace std;typedef long long ll;const int N = 100005;const int INF = 1100000000;int n, m, w;int a[N], tmp[N];bool judge(int h) {int cnt = 0;memset(tmp, 0, sizeof(tmp));for (int i = 0; i < n; i++) {if (i) tmp[i] += tmp[i - 1];if (a[i] + tmp[i] < h) {int add = h - tmp[i] - a[i];cnt += add;tmp[i] += add;tmp[min(i + w, n)] -= add;}if (cnt > m) return false;}return true;}int solve() {int l = 0, r = INF;while (l < r) {int mid = (l + r) / 2;if (judge(mid)) l = mid + 1;else r = mid; } return l - 1;}int main() {scanf("%d%d%d", &n, &m, &w); for (int i = 0; i < n; i++)  scanf("%d", &a[i]);printf("%d\n", solve());return 0;}

D:

#include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef long long ll;ll l, r, ans[10];int k, an = 0;void build() {    if (k == 1) ans[an++] = l;    else if (k == 2) {if (r - l + 1 == 2) {    if (l < (l^r)) ans[an++] = l;    else {ans[an++] = l; ans[an++] = r;}}else {    if (l%2) l++;    ans[an++] = l; ans[an++] = l + 1;}    }    else if (k == 3) {ll p = 1;while (p <= l) p *= 2;p /= 2;if (3 * p <= r) {    ans[an++] = l;    ans[an++] = l + p;    ans[an++] = 3 * p;}else {    if (l%2) l++;    ans[an++] = l;    ans[an++] = l + 1;}    }    else if (k == 4) {if (r - l + 1 > 4) {    if (l % 2) l++;    for (an = 0; an < 4; an++)ans[an] = l + an;}else {    ll Min = l;    ans[an++] = l;    for (int i = 1; i < 16; i++) {ll sum = 0;for (int j = 0; j < 4; j++) {    if (i&(1<<j)) sum ^= (l + j);}if (sum < Min) {    Min = sum;    an = 0;    for (int j = 0; j < 4; j++) {if (i&(1<<j))    ans[an++] = (l + j);    }}    }}    }    else {if (l % 2) l++;for (an = 0; an < 4; an++)    ans[an] = l + an;    }}int main() {    scanf("%lld%lld%d", &l, &r, &k);    build();    ll sum = 0;    for (int i = 0; i < an; i++)sum ^= ans[i];    printf("%lld\n", sum);    printf("%d\n", an);    for (int i = 0; i < an - 1; i++)printf("%lld ", ans[i]);    printf("%lld\n", ans[an - 1]);    return 0;}





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.