Codeforces Round #591 (Div. 2, based on Technocup 2020 Elimination Round 1)

Codeforces Round #591 (Div. 2, based on Technocup 2020 Elimination Round 1)

A. CME

  • 思路:n为偶数答案为0 n为奇数答案为1 特判下n为2时答案为2

  • 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 q, 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 >> q;
    while (q -- ){
        cin >> n;
        if (n == 2)
            cout << 2 << "\n";
        else if (n & 1)
            cout << 1 << "\n";
        else
            cout << 0 << "\n";
    }
    return 0;
}

B. Strings Equalization

  • 思路:只要两个串儿里有相同字符就可以让串s等价于串t

  • 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 q;
string s, 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 >> q;
    while (q -- ){
        cin >> s >> t;
        bool flag = false;
        for (int i = 0; i < s.length(); i ++ ){
            for (int j = 0; j < t.length(); j ++ ){
                if (s[i] == t[j]){
                    flag = true;
                    break;
                }
            }
            if (flag)
                break;
        }
        if (flag)
            cout << "YES\n";
        else
            cout << "NO\n";
    }
    return 0;
}

C. Save the Nature

  • 思路:p从大到小排序后 贪心+二分搞搞就行了(最近碰到这种题真的太多太多了

  • 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 q, n;
bool flag;
ll tmp, x, a, y, b, k, l, r, mid;
ll p[N];

inline bool cmp(const ll &a, const ll &b){
    return a > b;
}

inline bool check(ll mid){
    ll ans = 0;
    int pos = 1;
    for (int i = 1; i <= mid; i ++ )
        if (i % a == 0 && i % b == 0)
            ans += 0.01 * p[pos ++ ] * (x + y);
    for (int i = 1; i <= mid; i ++ )
        if (i % a == 0 && i % b != 0)
            ans += 0.01 * p[pos ++ ] * x;
    for (int i = 1; i <= mid; i ++ )
        if (i % a != 0 && i % b == 0)
            ans += 0.01 * p[pos ++ ] * y;
    return ans >= k;
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("my_in.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> q;
    while (q -- ){
        flag = false;
        cin >> n;
        l = 1, r = n;
        for (int i = 1; i <= n; i ++ )
            cin >> p[i];
        sort(p + 1, p + n + 1, cmp);
        cin >> x >> a >> y >> b >> k;
        if (x < y){
            swap(x, y);
            swap(a, b);
        }
        while (l <= r){
            mid = (l + r) >> 1;
            if (check(mid)){
                r = mid - 1;
                flag = true;
            }
            else
                l = mid + 1;
        }
        if (flag)
            cout << l << "\n";
        else
            cout << "-1\n";
    }
    return 0;
}

D. Sequence Sorting

  • 思路:记录不同值的左端点和右端点 然后找不相交的最长连续值

  • 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;

int q, n, a, R, res, ans;
int l[N], r[N];
set<int> st;

int main(){
#ifndef ONLINE_JUDGE
    freopen("my_in.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> q;
    while (q -- ){
        R = -1, res = 0, ans = 0;
        st.clear();
        cin >> n;
        for (int i = 1; i <= n; i ++ ){
            l[i] = n;
            r[i] = 1;
        }
        for (int i = 1; i <= n; i ++ ){
            cin >> a;
            l[a] = min(l[a], i);
            r[a] = max(r[a], i);
            st.insert(a);
        }
        for (auto a: st){
            if (l[a] > R)
                res ++ ;
            else
                res = 1;
            R = r[a];
            ans = max(ans, res);
        }
        cout << st.size() - ans << "\n";
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/Misuchii/p/11762569.html