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

    Educational Codeforces Round 76 (Rated for Div. 2)

    A. Two Rival Students

    • 思路:水题

    • 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, n, x, a, b, 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 >> n >> x >> a >> b;
    		ans = fabs(a - b);
    		ans += x;
    		if(ans > n - 1)
                ans = n - 1;
    		cout<< ans << '
    ';
    	}
        return 0;
    }
    

    B. Magic Stick

    • 思路:水题

    • 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, x, y;
    
    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 >> x >> y;
            if(x >= 4){
                cout << "YES
    ";
                continue;
            }
            if(x == 1){
                if(y == 1)
                    cout<<"YES
    ";
                else
                   cout<<"NO
    ";
            }
            else{
                if(y <= 3)
                  cout<<"YES
    ";
                else
                   cout<<"NO
    ";
            }
        }
        return 0;
    }
    

    C. Dominated Subarray

    • 思路:用set搞搞就行

    • 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 INF = 0x3f3f3f3f;
    const int N = 2e5 + 10;
    
    int t, n, ans;
    int a[N], b[N];
    set<int> s;
    
    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 -- ){
    		s.clear();
    		memset(b, 0, sizeof(b));
    		ans = INF;
    		cin >> n;
    		for (int i = 1; i <= n; i ++ )
    			cin >> a[i];
    		for (int i = 1; i <= n; i ++ ){
    			if (s.count(a[i]) == 1){
    				ans = min(ans, i - b[a[i]] + 1);
    				b[a[i]] = i;
    				continue;
    			}
    			s.insert(a[i]);
    			b[a[i]] = i;
    		}
    		if(ans == INF)
    			cout<<-1<<"
    ";
    		else
    			cout<<ans<<"
    ";
    	}
        return 0;
    }
    

    D. Yet Another Monster Killing Problem

    • 思路:贪心

    • 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 t, n, m, max1, max2, max3, now, pos, ans;
    int a[N], p[N], s[N];
    
    struct Hero{
        int p, s;
    }hero[N];
    
    inline bool cmp(const Hero &h1, const Hero &h2){
        return h1.p < h2.p;
    }
    
    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 -- ){
            max1 = 0, max2 = 0, max3 = 0, now = 1, ans = 1;
            cin >> n;
            for (int i = 1; i <= n; i ++ ){
                cin >> a[i];
                max1 = max(max1, a[i]);
            }
            cin >> m;
            for (int i = 1; i <= m; i ++ )
                cin >> hero[i].p >> hero[i].s;
            sort(hero + 1, hero + m + 1, cmp);
            if (max1 > hero[m].p){
                cout << "-1
    ";
                continue;
            }
            for (int i = m; i >= 1; i -- ){
                p[i] = hero[i].p;
                max2 = max(max2, hero[i].s);
                s[i] = max2;
            }
            for (int i = 1; i <= n; i ++ ){
                max3 = max(max3, a[i]);
                pos = lower_bound(p + 1, p + m + 1, max3) - p;
                if (s[pos] < (i - now + 1)){
                    now = i;
                    max3 = a[i];
                    ans ++ ;
                }
            }
            cout << ans << "
    ";
        }
        return 0;
    }
    

    E. The Contest

    • 思路:三个数组排个序拼成一个数组 答案即为n - LIS

    • 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 k1, k2, k3, n, ans, pos1, pos2;
    int a[N], b[N], c[N], res1[N], res2[N], tmp[N];
    
    int main(){
    #ifndef ONLINE_JUDGE
        freopen("my_in.txt", "r", stdin);
    #endif
        ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        cin >> k1 >> k2 >> k3;
        n = k1 + k2 + k3;
        ans = n;
        for (int i = 1; i <= k1; i ++ )
            cin >> a[i];
        for (int i = 1; i <= k2; i ++ )
            cin >> b[i];
        for (int i = 1; i <= k3; i ++ )
            cin >> c[i];
        sort(a + 1, a + k1 + 1);
        sort(b + 1, b + k2 + 1);
        sort(c + 1, c + k3 + 1);
        pos1 = 1;
        res1[0] = k1;
        for (int i = 1; i <= n; i ++ ){
            if (a[pos1] == i)
                pos1 ++ ;
            res1[i] = i - pos1 + 1 + k1 - pos1 + 1;
        }
        pos1 = k3, pos2 = k2;
        res2[n + 1] = k3;
        tmp[n + 1] = k3;
        for (int i = n; i > 0; i -- ){
            if (c[pos1] == i)
                pos1 -- ;
            else if (b[pos2] == i)
                pos2 -- ;
            res2[i] = pos1 + k2 - pos2;
            tmp[i] = min(res2[i], tmp[i + 1]);
        }
        for (int i = 0; i <= n; i ++ )
            ans = min(ans, res1[i] + tmp[i + 1] - (lower_bound(c + 1, c + k3 + 1, i) - c - 1));
        cout << ans << "
    ";
        return 0;
    }
    
  • 相关阅读:
    Saltstack module acl 详解
    Saltstack python client
    Saltstack简单使用
    P5488 差分与前缀和 NTT Lucas定理 多项式
    CF613D Kingdom and its Cities 虚树 树形dp 贪心
    7.1 NOI模拟赛 凸包套凸包 floyd 计算几何
    luogu P5633 最小度限制生成树 wqs二分
    7.1 NOI模拟赛 dp floyd
    springboot和springcloud
    springboot集成mybatis
  • 原文地址:https://www.cnblogs.com/Misuchii/p/11883899.html
Copyright © 2011-2022 走看看