zoukankan      html  css  js  c++  java
  • Codeforces Round #664 (Div. 2)

    都是模拟题, 写慢了, 还因为细节wa了2次, 不太行

    A

    没处理好最后一种情况, wa1次

    #include <bits/stdc++.h>
    #define all(n) (n).begin(), (n).end()
    #define se second
    #define fi first
    #define pb push_back
    #define mp make_pair
    #define sqr(n) (n)*(n)
    #define rep(i,a,b) for(int i=(a);i<=(b);++i)
    #define per(i,a,b) for(int i=(a);i>=(b);--i)
    #define IO ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> PII;
    typedef pair<ll, ll> PLL;
    typedef vector<int> VI;
    typedef double db;
     
    const int N = 1e5 + 5;
     
    int n, m, _, k;
     
    int main() {
        IO;
        for (cin >> _; _; --_) {
            int r, g, b, w; cin >> r >> g >> b >> w;
            ll c = r + g + b + w;
            int cnt = (r & 1) + (g & 1) + (b & 1);
     
            if (cnt == 0 || cnt == 3) {
                cout << "YES
    ";
            } else if (c & 1) {
                if (cnt == 2 && r && g && b) w += 3, cnt = 1;
     
                if (cnt == 2) cout << "NO
    ";
                else if (w & 1) cout << "NO
    ";
                else cout << "YES
    ";
            } else cout << "NO
    ";
        }
        return 0;
    }
    

    B

    #include <bits/stdc++.h>
    #define all(n) (n).begin(), (n).end()
    #define se second
    #define fi first
    #define pb push_back
    #define mp make_pair
    #define sqr(n) (n)*(n)
    #define rep(i,a,b) for(int i=(a);i<=(b);++i)
    #define per(i,a,b) for(int i=(a);i>=(b);--i)
    #define IO ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> PII;
    typedef pair<ll, ll> PLL;
    typedef vector<int> VI;
    typedef double db;
     
    const int N = 1e5 + 5;
     
    int n, m, _, k;
     
    int main() {
        IO;
            int x, y; cin >> n >> m >> x >> y;
            rep (j, y, m) cout << x << ' ' << j << '
    ';
            per (j, y - 1, 1) cout << x << ' ' << j << '
    '; 
            int xx = x;
            rep (j, 1, m) {
                rep (i, x, n) {
                    if (i == xx) continue;
                    cout << i << ' ' << j << '
    ';
                }
                per (i, x - 1, 1) {
                    if (i == xx) continue;
                    cout << i << ' ' << j << '
    ';
                }
                if (x != 1) x = 1;
                else x = n;
            }
        return 0;
    }
    

    C

    才2^9, 方法多了去了, 我这在 n,m较小的情况先 ll 也能跑

    #include <bits/stdc++.h>
    #define all(n) (n).begin(), (n).end()
    #define se second
    #define fi first
    #define pb push_back
    #define mp make_pair
    #define sqr(n) (n)*(n)
    #define rep(i,a,b) for(int i=(a);i<=(b);++i)
    #define per(i,a,b) for(int i=(a);i>=(b);--i)
    #define IO ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> PII;
    typedef pair<ll, ll> PLL;
    typedef vector<int> VI;
    typedef double db;
     
    const int N = 1e5 + 5;
     
    int n, m, _, k;
    VI b[201], c[201];
    int a[201];
     
    bool check(int k) {
        bool f = 1;
        rep(i, 1, n) {
            if ((1 << k) > a[i]) break;
            VI().swap(c[i]);
            for (int j : b[i])
                if (!((a[i] & j) >> k & 1)) c[i].pb(j);
            if (c[i].empty()) { f = 0; break; }
        }
        if (!f) return 0;
        rep(i, 1, n) {
            if ((1 << k) > a[i]) break;
            b[i].swap(c[i]);
        }
        return 1;
    }
     
    int main() {
        IO;
        cin >> n >> m;
        rep(i, 1, n) cin >> a[i], b[i].resize(m);
        rep(i, 0, m - 1) {
            cin >> b[1][i];
            rep(j, 2, n) b[j][i] = b[1][i];
        }
        sort(a + 1, a + 1 + n, greater<int>());
        int ans = 0;
        per(i, 30, 0) 
            if (!check(i)) 
                ans |= (1 << i);
        cout << ans;
        return 0;
    }
    

    D

    细节没处理好, wa 1次

    #include <bits/stdc++.h>
    #define all(n) (n).begin(), (n).end()
    #define se second
    #define fi first
    #define pb push_back
    #define mp make_pair
    #define sqr(n) (n)*(n)
    #define rep(i,a,b) for(int i=(a);i<=(b);++i)
    #define per(i,a,b) for(int i=(a);i>=(b);--i)
    #define IO ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> PII;
    typedef pair<ll, ll> PLL;
    typedef vector<int> VI;
    typedef double db;
    
    const int N = 1e5 + 5;
    
    int n, m, _, k;
    VI a, b;
    
    int main() {
        IO;
        cin >> n >> k >> m;
        rep(i, 1, n) {
            cin >> _;
            if (_ > m) a.pb(_);
            else b.pb(_);
        }
    
        ll ans = 0;
        if (a.empty() || a.size() == 1) {
            int i = 1;
            if (!a.empty()) ans += a[0], ++i;
            for (; i <= n; ++i) {
                if (b.empty()) break;
                ans += b.back(), b.pop_back();
            }
            cout << ans;
            return 0;
        }
    
        sort(all(a));
        sort(all(b));
    
        ans = a.back(); --n; a.pop_back();
    
        ll cur = 0;
        rep(i, 1, k + 1) {
            if (b.size() < i) break;
            cur += b[b.size() - i];
        }
    
        while (n >= k + 1 && !a.empty()) {
            if (a.back() <= cur) {
                ans += b.back();
                cur -= b.back();
                b.pop_back();
                if (b.size() >= k + 1) cur += b[b.size() - k - 1];
                --n;
            }
            else {
                ans += a.back(); a.pop_back();
                n -= (k + 1);
            }
        }
    
        rep(i, 1, n) {
            if (!b.empty())
                ans += b.back(), b.pop_back();
        }
    
        cout << ans;
        return 0;
    }
    
  • 相关阅读:
    iOS常用框架总结
    【Java】使用@Value @Reource或@Autowire依赖 (值) 注入时出现NPE的排查方法
    【Java】事件驱动模型和观察者模式
    新人训练营心得 - 道路阻且长
    【Java】Spring Web MVC注意事项
    【Linux】OpenWRT的无线设置注意事项——从2.4G到5G,hwmode不简单
    【Java】 Spring依赖注入小试牛刀:编写第一个Spring ApplicationContext Demo
    【Linux】 awk应用
    【C/C++】高亮C++中函数的重写——函数名相同?参数列表相同?返回值相同?
    【设计模式】C++单例模式的几种写法——Java自动加载内部类对象,C++怎么破?
  • 原文地址:https://www.cnblogs.com/2aptx4869/p/13493959.html
Copyright © 2011-2022 走看看