zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 77 (Rated for Div. 2)

    Educational Codeforces Round 77 (Rated for Div. 2)

    A. Heating

    • 思路:水题

    • AC代码


    #include <algorithm>
    #include <iomanip>
    #include <iostream>
    #include <map>
    #include <math.h>
    #include <queue>
    #include <set>
    #include <sstream>
    #include <stack>
    #include <stdio.h>
    #include <string.h>
    #include <string>
    typedef long long ll;
    typedef unsigned long long ull;
    using namespace std;
     
    ll mult_mod(ll x, ll y, ll mod){
        return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
    }
     
    ll pow_mod(ll a, ll b, ll p){
        ll res = 1;
        while (b){
            if (b & 1)
                res = mult_mod(res, a, p);
            a = mult_mod(a, a, p);
            b >>= 1;
        }
        return res % p;
    }
     
    ll gcd(ll a, ll b){
        return b ? gcd(b, a % b) : a;
    }
     
    int n;
    ll c, sum, ans;
     
    int main(){
    #ifndef ONLINE_JUDGE
        freopen("my_in.txt", "r", stdin);
    #endif
        ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        cin >> n;
        while (n -- ){
            ans = 0;
            cin >> c >> sum;
            if (sum % c == 0)
                ans = c * (sum / c) * (sum / c);
            else
                ans = (sum % c) * (sum / c + 1) * (sum / c + 1) + (c - sum % c) * (sum / c) * (sum / c); 
            cout << ans << "
    ";
        }
        return 0;
    }
    
    

    B. Obtain Two Zeroes

    • 思路:讨论即可

    • AC代码


    #include <algorithm>
    #include <iomanip>
    #include <iostream>
    #include <map>
    #include <math.h>
    #include <queue>
    #include <set>
    #include <sstream>
    #include <stack>
    #include <stdio.h>
    #include <string.h>
    #include <string>
    typedef long long ll;
    typedef unsigned long long ull;
    using namespace std;
    
    ll mult_mod(ll x, ll y, ll mod){
        return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
    }
    
    ll pow_mod(ll a, ll b, ll p){
        ll res = 1;
        while (b){
            if (b & 1)
                res = mult_mod(res, a, p);
            a = mult_mod(a, a, p);
            b >>= 1;
        }
        return res % p;
    }
    
    ll gcd(ll a, ll b){
        return b ? gcd(b, a % b) : a;
    }
    
    int t;
    ll a, b;
    
    int main(){
    #ifndef ONLINE_JUDGE
        freopen("my_in.txt", "r", stdin);
    #endif
        ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        cin >> t;
        while (t -- ){
            cin >> a >> b;
            if (a == b){
                if (a % 3 == 0)
                    cout << "YES
    ";
                else
                    cout << "NO
    ";
                continue;
            }
            if (a > b)
                swap(a, b);
            if (a == 1){
                if (b == 2)
                    cout << "YES
    ";
                else
                    cout << "NO
    ";
                continue;
            }
            ll tmp = b - a;
            if (2 * a < b)
                cout << "NO
    ";
            else if (2 * a == b)
                cout << "YES
    ";
            else{
                a -= tmp;
                if (a % 3 == 0)
                    cout << "YES
    ";
                else
                    cout << "NO
    ";
            }
        }
        return 0;
    }
    

    C. Infinite Fence

    • 思路:exgcd

    • AC代码


    #include <algorithm>
    #include <iomanip>
    #include <iostream>
    #include <map>
    #include <math.h>
    #include <queue>
    #include <set>
    #include <sstream>
    #include <stack>
    #include <stdio.h>
    #include <string.h>
    #include <string>
    typedef long long ll;
    typedef unsigned long long ull;
    using namespace std;
    
    ll mult_mod(ll x, ll y, ll mod){
        return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
    }
    
    ll pow_mod(ll a, ll b, ll p){
        ll res = 1;
        while (b){
            if (b & 1)
                res = mult_mod(res, a, p);
            a = mult_mod(a, a, p);
            b >>= 1;
        }
        return res % p;
    }
    
    ll gcd(ll a, ll b){
        return b ? gcd(b, a % b) : a;
    }
    
    ll lcm(ll a, ll b){
        return a / gcd(a, b) * b;
    }
    
    int t;
    ll r, b, k, lcm_, ans;
    
    int main(){
    #ifndef ONLINE_JUDGE
        freopen("my_in.txt", "r", stdin);
    #endif
        ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        cin >> t;
        while (t -- ){
            cin >> r >> b >> k;
            lcm_ = lcm(r, b);
            if (r > b)
                swap(r, b);
            ans = (lcm_ / r - 1 + lcm_ / b - 1) / (lcm_ / b);
            if (k > ans)
                cout << "OBEY
    ";
            else
                cout << "REBEL
    ";
        }
        return 0;
    }
    

    D. A Game with Traps

    • 思路:二分+贪心 对于前面有陷阱的时候 考虑拆掉这个陷阱 拆完之后判断是否被覆盖来决定往后还是往回走 覆盖用前缀和 差分处理

    • AC代码


    #include <algorithm>
    #include <iomanip>
    #include <iostream>
    #include <map>
    #include <math.h>
    #include <queue>
    #include <set>
    #include <sstream>
    #include <stack>
    #include <stdio.h>
    #include <string.h>
    #include <string>
    typedef long long ll;
    typedef unsigned long long ull;
    using namespace std;
    
    ll mult_mod(ll x, ll y, ll mod){
        return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
    }
    
    ll pow_mod(ll a, ll b, ll p){
        ll res = 1;
        while (b){
            if (b & 1)
                res = mult_mod(res, a, p);
            a = mult_mod(a, a, p);
            b >>= 1;
        }
        return res % p;
    }
    
    ll gcd(ll a, ll b){
        return b ? gcd(b, a % b) : a;
    }
    
    const int N = 2e5 + 10;
    
    int m, n, k, t, l, r;
    int a[N], cnt[N];
    
    struct Trap{
        int l, r, d;
    }trap[N];
    
    inline bool cmp(const int &a, const int &b){
        return a > b;
    }
    
    inline bool check(int mid){
        int tot = 0;
        int low = a[mid];
        memset(cnt, 0, sizeof(cnt));
        for (int i = 1; i <= k; i ++ ){
            if (trap[i].d > low){
                cnt[trap[i].l] ++ ;
                cnt[trap[i].r + 1] -- ;
            }
        }
        for (int i = 1; i <= n + 1; i ++ )
            cnt[i] += cnt[i - 1];
        for (int i = 0; i <= n + 1; i ++ )
            tot += (cnt[i] >= 1);
        return tot * 2 + n + 1 <= t;
    }
    
    int main(){
    #ifndef ONLINE_JUDGE
        freopen("my_in.txt", "r", stdin);
    #endif
        ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        cin >> m >> n >> k >> t;
        for (int i = 1; i <= m; i ++ )
            cin >> a[i];
        for (int i = 1; i <= k; i ++ )
            cin >> trap[i].l >> trap[i].r >> trap[i].d;
        sort(a + 1, a + m + 1, cmp);
        l = 0, r = m;
        while (l < r){
            int mid = (l + r + 1) >> 1;
            if (check(mid))
                l = mid;
            else
                r = mid - 1;
        }
        cout << l << "
    ";
        return 0;
    }
    

    E. Tournament

    • 思路:贪心 在第i轮 前(2^i - 1)个人必定淘汰 每次选花费最小即可

    • AC代码


    #include <algorithm>
    #include <iomanip>
    #include <iostream>
    #include <map>
    #include <math.h>
    #include <queue>
    #include <set>
    #include <sstream>
    #include <stack>
    #include <stdio.h>
    #include <string.h>
    #include <string>
    typedef long long ll;
    typedef unsigned long long ull;
    using namespace std;
    
    ll mult_mod(ll x, ll y, ll mod){
        return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
    }
    
    ll pow_mod(ll a, ll b, ll p){
        ll res = 1;
        while (b){
            if (b & 1)
                res = mult_mod(res, a, p);
            a = mult_mod(a, a, p);
            b >>= 1;
        }
        return res % p;
    }
    
    ll gcd(ll a, ll b){
        return b ? gcd(b, a % b) : a;
    }
    
    const int N = 3e5 + 10;
    
    ll n, ans;
    ll a[N];
    multiset<int> ms;
    
    int main(){
    #ifndef ONLINE_JUDGE
        freopen("my_in.txt", "r", stdin);
    #endif
        ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        cin >> n;
        for (int i = 1; i <= n; i ++ )
            cin >> a[i];
        for (int i = n; i >= 1 && a[i] != -1; i -- ){
            ms.insert(a[i]);
            if (!(i & (i - 1))){
                ans += *ms.begin();
                ms.erase(ms.begin());
            }
        }
        cout << ans << "
    ";
        return 0;
    }
    
  • 相关阅读:
    FileZilla
    dos2unix转换从win下vimruntime下的文件
    在 MFC SDI 程序中实现多语言程序界面
    AheadLib 2.2.150
    F982,F983班数理逻辑期末考试试题
    论文公式规范。
    Servlet/JSP配置详解
    COM沉思录(八)
    XML配置文件的读取处理
    天使和魔鬼(转载)
  • 原文地址:https://www.cnblogs.com/Misuchii/p/11965457.html
Copyright © 2011-2022 走看看