zoukankan      html  css  js  c++  java
  • Codeforces Round #644 (Div. 3)

    题目传送门

    还是视频题解。没什么好说的,题目感觉都比较简单。。但题量确实大。


    A. Minimal Square
    /*
     * Author:  heyuhhh
     * Created Time:  2020/5/25 9:56:17
     */
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <cmath>
    #include <set>
    #include <map>
    #include <queue>
    #include <iomanip>
    #include <assert.h>
    #define MP make_pair
    #define fi first
    #define se second
    #define pb push_back
    #define sz(x) (int)(x).size()
    #define all(x) (x).begin(), (x).end()
    #define INF 0x3f3f3f3f
    #define Local
    #ifdef Local
      #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
      void err() { std::cout << std::endl; }
      template<typename T, typename...Args>
      void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
      template <template<typename...> class T, typename t, typename... A> 
      void err(const T <t> &arg, const A&... args) {
      for (auto &v : arg) std::cout << v << ' '; err(args...); }
    #else
      #define dbg(...)
    #endif
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> pii;
    //head
    const int N = 1e5 + 5;
     
    void run() {
        int a, b; cin >> a >> b;
        if (a > b) swap(a, b);
        a *= 2;
        int n = max(a, b);
        cout << n * n << '
    ';
    }
     
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(0); cout.tie(0);
        cout << fixed << setprecision(20);
        int T; cin >> T; while(T--)
        run();
        return 0;
    }
    
    B. Honest Coach
    /*
     * Author:  heyuhhh
     * Created Time:  2020/5/25 9:59:00
     */
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <cmath>
    #include <set>
    #include <map>
    #include <queue>
    #include <iomanip>
    #include <assert.h>
    #define MP make_pair
    #define fi first
    #define se second
    #define pb push_back
    #define sz(x) (int)(x).size()
    #define all(x) (x).begin(), (x).end()
    #define INF 0x3f3f3f3f
    #define Local
    #ifdef Local
      #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
      void err() { std::cout << std::endl; }
      template<typename T, typename...Args>
      void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
      template <template<typename...> class T, typename t, typename... A> 
      void err(const T <t> &arg, const A&... args) {
      for (auto &v : arg) std::cout << v << ' '; err(args...); }
    #else
      #define dbg(...)
    #endif
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> pii;
    //head
    const int N = 1e5 + 5;
     
    void run() {
        int n; cin >> n;
        vector <int> a(n);
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        int d = INF;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i != j) d = min(d, abs(a[i] - a[j]));
            }
        }
        cout << d << '
    ';
    }
     
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(0); cout.tie(0);
        cout << fixed << setprecision(20);
        int T; cin >> T; while(T--)
        run();
        return 0;
    }
    
    C. Similar Pairs
    /*
     * Author:  heyuhhh
     * Created Time:  2020/5/25 9:48:00
     */
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <cmath>
    #include <set>
    #include <map>
    #include <queue>
    #include <iomanip>
    #include <assert.h>
    #define MP make_pair
    #define fi first
    #define se second
    #define pb push_back
    #define sz(x) (int)(x).size()
    #define all(x) (x).begin(), (x).end()
    #define INF 0x3f3f3f3f
    #define Local
    #ifdef Local
      #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
      void err() { std::cout << std::endl; }
      template<typename T, typename...Args>
      void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
      template <template<typename...> class T, typename t, typename... A> 
      void err(const T <t> &arg, const A&... args) {
      for (auto &v : arg) std::cout << v << ' '; err(args...); }
    #else
      #define dbg(...)
    #endif
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> pii;
    //head
    const int N = 50 + 5;
     
    void run() {
        int n; cin >> n;
        vector <int> a(n);
        for (int i = 0; i < n; i++) {
            cin >> a[i];   
        }
        sort(all(a));
        int cnt[2] = {0, 0};
        for (auto it : a) {
            ++cnt[it % 2];
        }
        if (cnt[0] % 2 == 0) {
            cout << "YES" << '
    ';
            return;
        }
        for (int i = 1; i < n; i++) {
            if (a[i] == a[i - 1] + 1) {
                cout << "YES" << '
    ';
                return;
            }
        }
        cout << "NO" << '
    ';
    }
     
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(0); cout.tie(0);
        cout << fixed << setprecision(20);
        int T; cin >> T; while(T--)
        run();
        return 0;
    }
    
    D. Buying Shovels
    /*
     * Author:  heyuhhh
     * Created Time:  2020/5/25 9:42:25
     */
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <cmath>
    #include <set>
    #include <map>
    #include <queue>
    #include <iomanip>
    #include <assert.h>
    #define MP make_pair
    #define fi first
    #define se second
    #define pb push_back
    #define sz(x) (int)(x).size()
    #define all(x) (x).begin(), (x).end()
    #define INF 0x3f3f3f3f
    #define Local
    #ifdef Local
      #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
      void err() { std::cout << std::endl; }
      template<typename T, typename...Args>
      void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
      template <template<typename...> class T, typename t, typename... A> 
      void err(const T <t> &arg, const A&... args) {
      for (auto &v : arg) std::cout << v << ' '; err(args...); }
    #else
      #define dbg(...)
    #endif
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> pii;
    //head
    const int N = 1e5 + 5;
     
    void run() {
        int n, k; cin >> n >> k;
        vector <int> d;
        for (int i = 1; 1ll * i * i <= n; i++) {
            if (n % i == 0) {
                d.push_back(i);
                if (i != n / i) d.push_back(n / i);
            }
        }
        sort(all(d));
        int p = upper_bound(all(d), k) - d.begin() - 1;
        cout << n / d[p] << '
    ';
    }
     
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(0); cout.tie(0);
        cout << fixed << setprecision(20);
        int T; cin >> T; while(T--)
        run();
        return 0;
    }
    
    E. Polygon
    /*
     * Author:  heyuhhh
     * Created Time:  2020/5/25 9:35:58
     */
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <cmath>
    #include <set>
    #include <map>
    #include <queue>
    #include <iomanip>
    #include <assert.h>
    #define MP make_pair
    #define fi first
    #define se second
    #define pb push_back
    #define sz(x) (int)(x).size()
    #define all(x) (x).begin(), (x).end()
    #define INF 0x3f3f3f3f
    #define Local
    #ifdef Local
      #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
      void err() { std::cout << std::endl; }
      template<typename T, typename...Args>
      void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
      template <template<typename...> class T, typename t, typename... A> 
      void err(const T <t> &arg, const A&... args) {
      for (auto &v : arg) std::cout << v << ' '; err(args...); }
    #else
      #define dbg(...)
    #endif
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> pii;
    //head
    const int N = 1e5 + 5;
     
    void run() {
        int n; cin >> n;
        vector <string> a(n);
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        auto ok = [&] (int i, int j) {
            return i + 1 >= n || j + 1 >= n || a[i + 1][j] == '1' || a[i][j + 1] == '1';   
        };
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) if (a[i][j] == '1') {
                if (ok(i, j)) {}
                else {
                    cout << "No" << '
    ';
                    return;
                }
            }
        }
        cout << "Yes" << '
    ';
    }
     
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(0); cout.tie(0);
        cout << fixed << setprecision(20);
        int T; cin >> T; while(T--)
        run();
        return 0;
    }
    
    F. Spy-string
    /*
     * Author:  heyuhhh
     * Created Time:  2020/5/24 22:33:18
     */
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <cmath>
    #include <set>
    #include <map>
    #include <queue>
    #include <iomanip>
    #include <assert.h>
    #define MP make_pair
    #define fi first
    #define se second
    #define pb push_back
    #define sz(x) (int)(x).size()
    #define all(x) (x).begin(), (x).end()
    #define INF 0x3f3f3f3f
    #define Local
    #ifdef Local
      #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
      void err() { std::cout << std::endl; }
      template<typename T, typename...Args>
      void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
      template <template<typename...> class T, typename t, typename... A> 
      void err(const T <t> &arg, const A&... args) {
      for (auto &v : arg) std::cout << v << ' '; err(args...); }
    #else
      #define dbg(...)
    #endif
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> pii;
    //head
     
    void run() {
        int n, m;
        cin >> n >> m;
        vector <string> s(n);
        for (int i = 0; i < n; i++) {
            cin >> s[i];
        }
        string res = s[0];
        auto chk = [&] (int k) {
            for (int i = 0; i < n; i++) {
                vector <int> p;
                for (int j = 0; j < m; j++) {
                    if (s[i][j] != res[j]) p.push_back(j);
                }
                if (sz(p) > 2) return false;
                if (sz(p) < 2) {
                    if (sz(p) == 1) {
                        if (p[0] != k) k = -1;
                    }
                    continue;
                }
                if (p[0] == k || p[1] == k) {
                    res[k] = s[i][k];
                    k = -1;
                } else return false;
            }
            return true;
        };
        for (int k = 0; k < m; k++) {
            res = s[0];
            if (chk(k)) {
                cout << res << '
    ';
                return;
            }
        }
        cout << -1 << '
    ';
    }
     
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(0); cout.tie(0);
        cout << fixed << setprecision(20);
        int T; cin >> T; while(T--)
        run();
        return 0;
    }
    
    G. A/B Matrix
    /*
     * Author:  heyuhhh
     * Created Time:  2020/5/24 22:24:07
     */
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <cmath>
    #include <set>
    #include <map>
    #include <queue>
    #include <iomanip>
    #include <assert.h>
    #define MP make_pair
    #define fi first
    #define se second
    #define pb push_back
    #define sz(x) (int)(x).size()
    #define all(x) (x).begin(), (x).end()
    #define INF 0x3f3f3f3f
    #define Local
    #ifdef Local
      #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
      void err() { std::cout << std::endl; }
      template<typename T, typename...Args>
      void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
      template <template<typename...> class T, typename t, typename... A> 
      void err(const T <t> &arg, const A&... args) {
      for (auto &v : arg) std::cout << v << ' '; err(args...); }
    #else
      #define dbg(...)
    #endif
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> pii;
    //head
    const int N = 1e5 + 5;
     
    void run() {
        int n, m, a, b; cin >> n >> m >> a >> b;
        vector <vector <int>> mat(n, vector <int> (m));
        vector <int> cols(m);
        for (int i = 0, p = 0; i < n; i++) {
            for (int j = p; j < p + a; j++) {
                 mat[i][j % m] = 1;
                 ++cols[j % m];
            }
            p += a;
        }
        for (int i = 0; i < m; i++) {
            if (cols[i] != b) {
                cout << "NO" << '
    ';
                return;
            }
        }
        cout << "YES" << '
    ';
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                cout << mat[i][j];
            }
            cout << '
    ';
        }
    }
     
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(0); cout.tie(0);
        cout << fixed << setprecision(20);
        int T; cin >> T; while(T--)
        run();
        return 0;
    }
    
    H. Binary Median
    /*
     * Author:  heyuhhh
     * Created Time:  2020/5/24 22:00:13
     */
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <cmath>
    #include <set>
    #include <map>
    #include <queue>
    #include <iomanip>
    #include <assert.h>
    #define MP make_pair
    #define fi first
    #define se second
    #define pb push_back
    #define sz(x) (int)(x).size()
    #define all(x) (x).begin(), (x).end()
    #define INF 0x3f3f3f3f
    #define Local
    #ifdef Local
      #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
      void err() { std::cout << std::endl; }
      template<typename T, typename...Args>
      void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
      template <template<typename...> class T, typename t, typename... A> 
      void err(const T <t> &arg, const A&... args) {
      for (auto &v : arg) std::cout << v << ' '; err(args...); }
    #else
      #define dbg(...)
    #endif
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> pii;
    //head
    const int N = 100 + 5, M = 65;
     
    int n, m;
     
    void run() {
        cin >> n >> m;
        ll k = (1ll << m);
        vector <ll> a;
        map <ll, int> mp;
        for (int i = 1; i <= n; i++) {
            string s; cin >> s;
            reverse(all(s));
            ll x = 0, pow2 = 1;
            for (int i = 0; i < s.length(); i++) {
                x += pow2 * (s[i] - '0');
                pow2 *= 2;
            }
            a.push_back(x);
        }
        sort(all(a));
        ll p = (k - 1) / 2;
        for (int i = 0; i < sz(a); i++) {
            mp[a[i]] = 1;
            --k;
            if (k % 2 == 0) {
                if (a[i] >= p) {
                    --p;
                    while (mp[p]) --p;
                }
            } else if(a[i] <= p) {
                ++p;
                while (mp[p]) ++p;
            }
        }
        string res = "";
        for (int i = 0; i < m; i++) {
            if (p >> i & 1) res += '1';
            else res += '0';
        }
        reverse(all(res));
        cout << res << '
    ';
    }
     
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(0); cout.tie(0);
        cout << fixed << setprecision(20);
        int T; cin >> T; while(T--)
        run();
        return 0;
    }
    
  • 相关阅读:
    POJ 3261 Milk Patterns (求可重叠的k次最长重复子串)
    UVaLive 5031 Graph and Queries (Treap)
    Uva 11996 Jewel Magic (Splay)
    HYSBZ
    POJ 3580 SuperMemo (Splay 区间更新、翻转、循环右移,插入,删除,查询)
    HDU 1890 Robotic Sort (Splay 区间翻转)
    【转】ACM中java的使用
    HDU 4267 A Simple Problem with Integers (树状数组)
    POJ 1195 Mobile phones (二维树状数组)
    HDU 4417 Super Mario (树状数组/线段树)
  • 原文地址:https://www.cnblogs.com/heyuhhh/p/12956344.html
Copyright © 2011-2022 走看看