Codeforces 460D Little Victor and Set (constructed), codeforces460d

Source: Internet
Author: User

Codeforces 460D Little Victor and Set (constructed), codeforces460d

Link: Codeforces 460D Little Victor and Set

For a given range of l and r, select a number smaller than k to minimize or equal to these numbers.

Solution: If k is an even number, then kXOR (k + 1) = 1
Based on this, all the situations where k is less than 3 can be processed.
For k = 3, find a 2 k greater than l. If the value is 2 k + 1 ≤ r, you can create three numbers or the value is 0.

#include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef long long ll;ll l, r, k;void solve (int n) {    int s = 1;    ll ret = l;    for (int i = 2; i < (1<<n); i++) {        ll u = 0;        for (int j = 0; j < n; j++)            if (i&(1<<j))                u ^= (l+j);        if (u < ret) {            ret = u;            s = i;        }    }    int x = 0;    ll arr[10];    for (int i = 0; i < n; i++)        if (s&(1<<i))            arr[x++] = l + i;    printf("%lld\n%d\n", ret, x);    printf("%lld", arr[0]);    for (int i = 1; i < x; i++)        printf(" %lld", arr[i]);    printf("\n");}void fuck () {    ll x = 1;    while (x <= l) x <<= 1;    if ((x | (x>>1)) <= r) {        printf("0\n3\n");        printf("%lld %lld %lld\n", l, x | (x>>1), (x | (x>>1)) ^ l);        return;    }    printf("1\n2\n");    if (l&1)        l++;    printf("%lld %lld\n", l, l+1);}int main () {    scanf("%lld%lld%lld", &l, &r, &k);    if (k == 1)        printf("%lld\n1\n%lld\n", l, l);    else if (k >= 5) {        if (l&1)            l++;        printf("0\n4\n%lld %lld %lld %lld\n", l, l+1, l+2, l+3);    } else if (k == 4 && (r - l + 1 > 4 || l%2 == 0)) {        if (l&1)            l++;        printf("0\n4\n%lld %lld %lld %lld\n", l, l+1, l+2, l+3);    } else if (k == 2 && (r - l + 1 > 2 || l%2 == 0)) {        if (l&1)            l++;        printf("1\n2\n%lld %lld\n", l, l+1);    } else if (k == 2) {        if ((l^r) > l)            printf("%lld\n1\n%lld\n", l, l);        else            printf("%lld\n2\n%lld %lld\n", l^r, l, r);    } else if (k == 4) {        solve(k);    } else {        fuck();    }    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.