cf591div2abc

cf遭到了 ddos 攻击, 所有三天内的所有比赛 unrated, 难受~~~   wxhtxdy(破音~~~)

https://codeforces.com/contest/1223/problem/A

观察以后会发现 n 为奇数时可以变成 1 + x = n-x  (x=(n-1)/2) 输出1 , n为偶数的时候可以变成 1 +x = n-x-1 输出0, 但是有个例外 n =2 时 需要 1+1=2 输出2

#include<bits/stdc++.h>

using namespace std;

int main(){
    int t; cin >>t;
    while(t--) {
        int n; cin>>n; 
        cout<<((n==2)? 2 : n&1) << endl;
    }
    return 0;
}

https://codeforces.com/contest/1223/problem/B

Note that you can also apply this operation to the string t.

题意: 两个字符串 每次可以进行两个字符的赋值 比如 abcd -> aacd, 问是否能将 s 变成 t

关键是 s 与 t 都能进行任意次的赋值, 所以无论s t 是啥, 只有里面有相同的字符 就能都变成 单个字符的字符串, s t 有相同字符则YES

/*
3
xabb
aabx
technocup
technocup
a
z

YES
YES
NO
*/
#include<bits/stdc++.h>
using namespace std;
#define _for(i,a,b) for(int i = (a); i < (b); i++)    
#define _rep(i,a,b) for(int i = (a); i <= (b); i++)

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int t; cin>>t;
    while(t--){
        string s,t; cin>>s>>t; 
        int n = s.size(), a = 0, b = 0;
        _for(i,0,n) a |= (1<<(s[i]-'a'));
        _for(i,0,n) b |= (1<<(t[i]-'a'));
        cout<<((a&b) ? "YES
": "NO
");
    }
    return 0;
}

https://codeforces.com/contest/1223/problem/C

题意:输入 p1 p2 p3…… pn, 每隔a个p乘x  每隔b个p乘y   其他乘0, 问最少小的区间段之和 大于 k

当时一开始想的是先排序p数组, 再枚举n/min(a,b)  每次判断其中多少个  a b的倍数 从大到小 乘p, 输出最小符合的 数,但是太麻烦了 不会写

题解做法是二分区间,利用区间a b 倍数赋值 再排序, 再取区间和 大于 k 的最小区间, 具体二分的边界条件可以手推下

#include<bits/stdc++.h>
using namespace std;

#define _for(i,a,b) for(int i = (a); i < (b); i++)
#define _rep(i,a,b) for(int i = (a); i <= (b); i++)
const int N = 2e5+100;
int t,n,x,y,a,b,p[N],c[N];

int main(){
    scanf("%d", &t);
    while(t--) {
        scanf("%d", &n);
        _for(i,0,n) scanf("%d", &p[i]), p[i] /= 100;
        scanf("%d%d", &x, &a);
        scanf("%d%d", &y, &b);
        long long k;scanf("%lld", &k);
        sort(p, p+n); reverse(p, p+n);
        int l = 0, r = n;
        while(l < r) {//
            int mid = (l+r)>>1;
            _rep(i,1,mid+1) {
                int z = 0;
                if(i%a == 0) z += x;
                if(i%b == 0) z += y;
                c[i-1] = z;
            }
            sort(c, c+mid); reverse(c, c+mid);
            long long sum = 0;
            _for(i,0,mid) sum += 1ll*c[i]*p[i];
            if(sum >= k) r = mid; else l = mid;
        }
        if(r <= n)printf("%d
", r); else printf("-1
");
    }
    return 0;
}
/*
4
1
100
50 1
49 1
100
8
100 200 100 200 100 200 100 100
10 2
15 3
107
3
1000000000 1000000000 1000000000
50 1
50 1
3000000000
5
200 100 100 100 100
69 5
31 2
90

*/
原文地址:https://www.cnblogs.com/163467wyj/p/11633064.html