zoukankan      html  css  js  c++  java
  • AtCoder Beginner Contest 169

    题目传送门

    视频题解

    BC是一些常见的技巧,D题很水,E比较有意思,考虑成为中位数的充要条件即可,主要是注意到某些不与相交的区间个数。F的话是一个不是很难的dp,把计算过程分散到dp过程即可。具体的话可以看看视频题解。


    以下是代码:

    A - Multiplication 1
    /*
     * Author:  heyuhhh
     * Created Time:  2020/5/31 20:00:31
     */
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <cmath>
    #include <set>
    #include <map>
    #include <queue>
    #include <iomanip>
    #include <assert.h>
    #include <functional>
    #include <numeric>
    #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;
        cout << a * b << '
    ';
    }
    
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(0); cout.tie(0);
        cout << fixed << setprecision(20);
        run();
        return 0;
    }
    
    
    B - Multiplication 2
    /*
     * Author:  heyuhhh
     * Created Time:  2020/5/31 20:01:06
     */
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <cmath>
    #include <set>
    #include <map>
    #include <queue>
    #include <iomanip>
    #include <assert.h>
    #include <functional>
    #include <numeric>
    #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;
    const ll MAX = 1e18;
    
    void run() {
        int n; cin >> n;
        vector <ll> a(n);
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        for (int i = 0; i < n; i++) if (a[i] == 0) {
            cout << 0 << '
    ';
            return;
        }
        ll ans = 1;
        for (int i = 0; i < n; i++) {
            if (a[i] > MAX / ans) {
                cout << -1 << '
    ';
                return;
            }
            ans *= a[i];
        }
        cout << ans << '
    ';
    }
    
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(0); cout.tie(0);
        cout << fixed << setprecision(20);
        run();
        return 0;
    }
    
    
    C - Multiplication 3
    /*
     * Author:  heyuhhh
     * Created Time:  2020/5/31 20:11:10
     */
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <cmath>
    #include <set>
    #include <map>
    #include <queue>
    #include <iomanip>
    #include <assert.h>
    #include <functional>
    #include <numeric>
    #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;
    const double eps = 1e-7;
    
    void run() {
        ll A;
        double B;
        cin >> A >> B;
        ll C = ll(B * 100 + 0.5);
        ll ans = A * C;
        cout << ll(ans / 100) << '
    ';
    }
    
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(0); cout.tie(0);
        cout << fixed << setprecision(20);
        run();
        return 0;
    }
    
    
    D - Div Game
    /*
     * Author:  heyuhhh
     * Created Time:  2020/5/31 20:16:37
     */
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <cmath>
    #include <set>
    #include <map>
    #include <queue>
    #include <iomanip>
    #include <assert.h>
    #include <functional>
    #include <numeric>
    #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() {
        ll n; cin >> n;
        int ans = 0;
        for (int i = 2; 1ll * i * i <= n; i++) {
            if (n % i == 0) {
                int cnt = 0;
                int tot = 1;
                while (n % i == 0) {
                    n /= i;
                    ++cnt;  
                    if (cnt == tot) {
                        cnt = 0;
                        ++ans;
                        ++tot;  
                    } 
                }
            }   
        }
        if (n > 1) ++ans;
        cout << ans << '
    ';
    }
    
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(0); cout.tie(0);
        cout << fixed << setprecision(20);
        run();
        return 0;
    }
    
    
    E - Count Median
    /*
     * Author:  heyuhhh
     * Created Time:  2020/5/31 20:46:05
     */
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <cmath>
    #include <set>
    #include <map>
    #include <queue>
    #include <iomanip>
    #include <assert.h>
    #include <functional>
    #include <numeric>
    #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 = 2e5 + 5;
    
    struct seg {
        int l, r;   
    }a[N];
    
    int n;
    
    int findL(int k) {
        return a[k + 1].r;
    }
    
    int findR(int k) {
        return a[k + 1].l;
    }
    
    seg find(int k) {
        sort(a + 1, a + n + 1, [&](seg A, seg B) {
            return A.r < B.r;
        });
        int r = findL(k - 1);
        sort(a + 1, a + n + 1, [&](seg A, seg B) {
            return A.l > B.l;
        });   
        int l = findR(n - k);
        return seg{l, r};
    }
    
    void run() {
        cin >> n;
        for (int i = 1; i <= n; i++) {
            int l, r; cin >> l >> r;
            a[i] = seg{l, r};
        }
        if (n & 1) {
            seg res = find(n / 2 + 1);
            int ans = max(0, res.r - res.l + 1); 
            cout << ans << '
    ';
        } else {
            seg res1 = find(n / 2), res2 = find(n / 2 + 1);
            int Min = res1.l + res2.l, Max = res1.r + res2.r;
            int ans = max(0, Max - Min + 1);
            cout << ans << '
    ';
        }
    }
    
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(0); cout.tie(0);
        cout << fixed << setprecision(20);
        run();
        return 0;
    }
    
    
    F - Knapsack for All Subsets
    /*
     * Author:  heyuhhh
     * Created Time:  2020/5/31 21:11:22
     */
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <cmath>
    #include <set>
    #include <map>
    #include <queue>
    #include <iomanip>
    #include <assert.h>
    #include <functional>
    #include <numeric>
    #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 = 3000 + 5, MOD = 998244353;
    int qpow(ll a, ll b) {
        ll res = 1;
        while (b) {
            if (b & 1) res = res * a % MOD;
            a = a * a % MOD;
            b >>= 1;
        }   
        return res;
    }
    
    int n, s;
    int a[N];
    int dp[N][N];
    
    void add(int& x, int y) {
        x += y;
        if (x >= MOD) x -= MOD;   
    }
    
    void run() {
        cin >> n >> s;
        for (int i = 1; i <= n; i++) {
            cin >> a[i];
        }
        dp[0][0] = qpow(2, n);
        int inv2 = (MOD + 1) / 2;
        for (int i = 1; i <= n; i++) {
            for (int j = 0; j <= s; j++) {
                if (j >= a[i]) {
                    dp[i][j] = 1ll * dp[i - 1][j - a[i]] * inv2 % MOD;
                }
                dp[i][j] = (dp[i][j] + dp[i - 1][j]) % MOD;
            }
        }
        cout << dp[n][s] << '
    ';
    }
    
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(0); cout.tie(0);
        cout << fixed << setprecision(20);
        run();
        return 0;
    }
    
    
  • 相关阅读:
    104_如何彻底删除VMware
    学习笔记(25)- NLP的几个概念
    学习笔记(24)- plato-训练中文模型
    学习笔记(23)- plato-准备中文语料
    学习笔记(22)- plato-训练端到端的模型
    学习笔记(21)- texar 文本生成
    学习笔记(35)-安装pyhanlp
    NLP直播-1 词向量与ELMo模型
    线上学习-语言模型 language model
    学习笔记(20)- Google LaserTagger
  • 原文地址:https://www.cnblogs.com/heyuhhh/p/13027759.html
Copyright © 2011-2022 走看看