zoukankan      html  css  js  c++  java
  • 2019 ICPC Asia Xuzhou Regional

    A. Cat

    异或和重要性质:每个偶数和相邻的大于它的奇数的异或结果恒为1。

    所以每四个以偶数开头的连续的数异或结果为0。 

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    ll a[111];
    int main()
    {
        int t;
        scanf("%d", &t);
        while(t--)
        {
            ll l, r, s, ans = 0, tmp = 0;
            scanf("%lld %lld %lld", &l, &r, &s);
            if(r - l + 1 >= 4)
            {
                ll lx;
                for(ll i = l; i <= r; ++i)
                {
                    if(i % 4 == 0)
                    {
                        lx = i;
                        break;
                    }
                }
                ll rx = (r + 1 - lx) / 4 * 4 + lx; //反例:比如4,5,6,7,8,9,10,11
                ll cnt = 0;
                for(ll i = l; i < lx; ++i) a[++cnt] = i;
                for(ll i = rx; i <= r; ++i) a[++cnt] = i;
                for(ll i = 1; i <= cnt; ++i)
                {
                    tmp = 0;
                    for(ll j = i; j <= cnt; ++j)  //注意异或不具有单调性,所以tmp > s时不能退出,以后可能还会 < s
                    {
                        tmp ^= a[j];
                        if(tmp <= s)
                            ans = max(ans, j - i + 1);
                    }
                }
                ans += (rx - lx);
            }
            else
            {
                for(ll i = l; i <= r; ++i)
                {
                    tmp = 0;
                    for(ll j = i; j <= r; ++j)
                    {
                        tmp ^= j;
                        if(tmp <= s)
                            ans = max(ans, j - i + 1);
                    }
                }
            }
            if(ans == 0) printf("-1
    ");
            else printf("%lld
    ", ans);
        }
    }

    C. <3 numbers

    小区间暴力,大区间直接Yes。

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int maxn = 1e6 + 5;
    bool is_prime(ll n)
    {
        if(n == 1) return true;
        for(ll i = 2; i <= sqrt(n); ++i)
            if(n % i == 0) return false;
        return true;
    }
    int main()
    {
        int t;
        cin >> t;
        while(t--)
        {
            int cnt = 0;
            int l, r;
            scanf("%d %d", &l, &r);
            if(r - l + 1 > 1000)
            {
                printf("Yes
    ");
                continue;
            }
            for(int i = l; i <= r; ++i)
            {
                if(is_prime(i)) ++cnt;
            }
            if(3 * cnt < (r - l + 1)) printf("Yes
    ");
            else printf("No
    ");
        }
    }

    F. The Answer to the Ultimate Question of Life, The Universe, and Everything.

    暴力打表。 

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int maxn = 222;
    ll a[maxn][3] = {{-5000, 0, 5000}, {-5000, 1, 5000}, {-4373, -486, 4375}, {-5, 4, 4}, {-5001, 0, 0}, {-5001, 0, 0}, {-637, -205, 644}, {-169, 44, 168}, {-5000, 2, 5000}, {-216, -52, 217}, {-650, -353, 683}, {-695, -641, 843}, {-11, 7, 10}, {-5001, 0, 0}, {-5001, 0, 0}, {-265, -262, 332}, {-4114, -588, 4118}, {-3331, 2195, 2977}, {-1373, -1276, 1671}, {-95, 47, 91}, {-2816, -741, 2833}, {-401, -287, 445}, {-5001, 0, 0}, {-5001, 0, 0}, {-10, 8, 8}, {-2683, 1839, 2357}, {-2107, 237, 2106}, {-5000, 3, 5000}, {-2268, -249, 2269}, {-233, -69, 235}, {-5001, 0, 0}, {-5001, 0, 0}, {-5001, 0, 0}, {-5001, 0, 0}, {-1555, -244, 1557}, {-1120, -509, 1154}, {-3223, 2358, 2731}, {-444, -84, 445}, {-27, 16, 25}, {-5001, 0, 0}, {-5001, 0, 0}, {-5001, 0, 0}, {-5001, 0, 0}, {-823, -307, 837}, {-7, -5, 8}, {-2369, 1709, 2025}, {-758, -473, 815}, {-141, 49, 139}, {-3950, -1247, 3991}, {-5001, 0, 0}, {-5001, 0, 0}, {-796, 602, 659}, {-5001, 0, 0}, {-2370, 1518, 2141}, {-3885, -648, 3891}, {-3329, 1837, 3131}, {-672, 505, 559}, {-998, 361, 982}, {-5001, 0, 0}, {-5001, 0, 0}, {-1201, -163, 1202}, {-966, 668, 845}, {-2744, -1561, 2903}, {-161, 102, 146}, {-5000, 4, 5000}, {-929, 403, 903}, {1, 1, 4}, {-5001, 0, 0}, {-5001, 0, 0},{-403, 134, 398}, {-2359, 824, 2325}, {-533, 401, 443}, {-432, -104, 434}, {-335, -146, 344}, {-5001, 0, 0}, {-5001, 0, 0}, {-5001, 0, 0}, {-5001, 0, 0}, {-2080, -829, 2123}, {-706, -196, 711}, {-1300, -706, 1366}, {-2368, -1719, 2638}, {-1317, 847, 1188}, {-3707, 1315, 3651}, {-5001, 0, 0}, {-5001, 0, 0}, {-5001, 0, 0}, {-4126, -1972, 4271}, {-1390, -1282, 1686}, {-2514, 1953, 2036}, {-1803, 365, 1798}, {-3389, -2912, 3992}, {-4052, 861, 4039}, {-248, -98, 253}, {-5001, 0, 0}, {-5001, 0, 0}, {-22, 14, 20}, {-3168, -991, 3200}, {-2101, -1638, 2391}, {-893, -622, 984}, {-1797, -903, 1870}, {-2327, 319, 2325}, {-239, 118, 229}, {-5001, 0, 0}, {-5001, 0, 0}, {-7, -4, 8}, {-2689, -1165, 2760}, {-1309, 947, 1117}, {-1165, -948, 1345}, {-2948, 853, 2924}, {-5001, 0, 0}, {-4793, -2312, 4966}, {-5001, 0, 0}, {-5001, 0, 0}, {-5001, 0, 0}, {-12, 8, 11}, {-1906, -757, 1945}, {-896, -555, 962}, {-4328, 383, 4327}, {-3677, -1673, 3789}, {-2804, 1219, 2725}, {-5001, 0, 0}, {-5001, 0, 0}, {-37, -16, 38}, {-1, 0, 5}, {-5000, 5, 5000}, {-2212, -419, 2217}, {-4034, -3881, 4988}, {-3989, -726, 3997}, {-1580, -1238, 1801}, {-5001, 0, 0}, {-5001, 0, 0}, {-1, 2, 5}, {-399, 167, 389}, {-3013, -1766, 3203}, {-1351, -629, 1395}, {-1116, 816, 946}, {-758, -428, 801}, {-86, -77, 103}, {-5001, 0, 0}, {-5001, 0, 0}, {-139, 104, 116}, {-7, -3, 8}, {-5001, 0, 0}, {-2746, -2552, 3342}, {-8, -7, 10}, {-327, -263, 376}, {-2366, 1528, 2131}, {-5001, 0, 0}, {-5001, 0, 0}, {-367, 260, 317}, {-463, 215, 447}, {-805, 486, 741}, {-3736, -695, 3744}, {-2135, -516, 2145}, {-3693, -1049, 3721}, {-5001, 0, 0}, {-5001, 0, 0}, {-5001, 0, 0}, {-1534, 383, 1526}, {-3874, -1654, 3972}, {-4767, -2476, 4980}, {-4125, -1417, 4180}, {-3423, -2943, 4033}, {-66, -59, 79}, {-5001, 0, 0}, {-5001, 0, 0}, {-5001, 0, 0}, {-802, -574, 890}, {-1354, -1012, 1521}, {-3834, -2149, 4047}, {-1328, 891, 1178}, {-5001, 0, 0}, {-5001, 0, 0}, {-335, -170, 349}, {-5001, 0, 0}, {-5001, 0, 0}, {-1168, -160, 1169}, {-13, -10, 15}, {-2839, 1503, 2691}, {-5001, 0, 0}, {-4874, 974, 4861}, {-90, -29, 91}, {-4889, 976, 4876}, {-5001, 0, 0}, {-5001, 0, 0}, {-4, 5, 5}, {-1885, -1092, 2000}, {-1639, 318, 1635}, {-1702, -1403, 1974}, {-4812, -593, 4815}, {-377, -215, 399}, {-20, 16, 16}, {-5001, 0, 0}, {-5001, 0, 0}, {-5001, 0, 0}, {-1057, -579, 1112}, {-2867, -1606, 3026}, {-3752, -1347, 3809}, {-2208, 508, 2199}, {-2318, -638, 2334}};
    
    int main()
    {
        int t;
        cin >> t;
        while(t--)
        {
            int x;
            scanf("%d", &x);
            if(a[x][0] == -5001) printf("impossible
    ");
            else printf("%d %d %d
    ", a[x][0], a[x][1], a[x][2]);
        }
    }
  • 相关阅读:
    从小知识开始练习
    shell的基本语法
    shell的一些简单用法
    HTML 父元素与子元素之间的margin-top问题
    HTML input文本框设置和移除默认值
    c# winform进入窗口后在文本框里的默认焦点
    c#面向对象基础 重写、虚方法、抽象类
    c#面向对象基础 封装、继承
    c#面向对象基础 静态成员、构造函数、命名空间与类库
    c#面向对象基础 类、方法、方法重载
  • 原文地址:https://www.cnblogs.com/Maxx-el/p/14132684.html
Copyright © 2011-2022 走看看