Codeforces Round #609 (Div. 2)【A - D】

题目来源:https://codeforces.com/contest/1269

这场可以上分的,可惜没打。不过虚拟参与的时候也有很多问题,比如B题疯狂WA,写的也特别慢,最后三题,打完后补了一题。E题感觉有点复杂,不是我这个水平该写的


1269A - Equation

题目要找满足的a和b使a-b=n 不妨设 a=(x+1) * n,b=x * n 我们按题目的要求适当的设置一个x就好了
值得注意的是n为质数或1的情况 不能随便设 第一个样例给了一个好开头 让a=9 * n,b=8 * n恰到好处

#include
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#define ls k<<1,l,mid
#define rs k<<1|1,mid+1,r
#define r(x) read(x)
#define rrr(x, y, z) read(x);read(y);read(z)
#define mp(x, y) make_pair(x,y)
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define FOR(i, l, r) for(int i=l;i<=r;i++)
using namespace std;

const int N = 5e5 + 5;
const int M = 1e3 + 5;
const int mod = 1e9 + 7;
const int INF = 0x7fffffff;
const int SZ = 17;
const double eps = 1e-8;
const double PI = acos(-1);
typedef long long LL;
typedef pair<int, int> pt;

int n, m;

template<class T>
inline void read(T &x) {
    char c;
    x = 1;
    while ((c = getchar()) < '0' || c > '9') if (c == '-') x = -1;
    T res = c - '0';
    while ((c = getchar()) >= '0' && c <= '9') res = res * 10 + c - '0';
    x *= res;
}

int main() {
    int t;
        r(n);
        cout<<9*n<<' '<<8*n<<endl;

    return 0;
}

1269B - Modulo Equality

据说这题通过一些字符串匹配算法 直接O(n)解决 ,我是暴力O(n^2)写的
思路的话:不管加多少,如果能成功匹配,那串f的第一个元素一定会变成串g的某一个元素,枚举这个n次,然后判断匹配不匹配n次 复杂度O(n^2) 记得排序

#include
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#define ls k<<1,l,mid
#define rs k<<1|1,mid+1,r
#define r(x) read(x)
#define rrr(x, y, z) read(x);read(y);read(z)
#define mp(x, y) make_pair(x,y)
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define FOR(i, l, r) for(int i=l;i<=r;i++)
using namespace std;

const int N = 1e5 + 5;
const int M = 1e3 + 5;
const int mod = 1e9 + 7;
const int INF = 0x7fffffff;
const int SZ = 17;
const double eps = 1e-8;
const double PI = acos(-1);
typedef long long LL;
typedef pair<int, int> pt;

int n, m;
int f[N], g[N];

template<class T>
inline void read(T &x) {
    char c;
    x = 1;
    while ((c = getchar()) < '0' || c > '9') if (c == '-') x = -1;
    T res = c - '0';
    while ((c = getchar()) >= '0' && c <= '9') res = res * 10 + c - '0';
    x *= res;
}

int main() {
    r(n); r(m);
    FOR(i, 1, n) r(f[i]);
    FOR(i, 1, n) r(g[i]);
    sort(f + 1, f + n + 1);
    sort(g + 1, g + n + 1);
    int ans = INF;
    FOR(i, 1, n) {
        g[i + n] = g[i];
    }
    FOR(i, 1, n) {
        int gg = (g[i] - f[1] + m) % m;
        bool flag = 1;
        FOR(j, 2, n) {
            if ((f[j] + gg) % m != g[j+i-1]) {
                flag = 0;
                break;
            }
        }
        if (flag) ans = min(ans, gg);
    }
    cout << ans << endl;
    return 0;
}

1269C - Long Beautiful Integer

以前m个数为周期 循环到n个数 如果这个序列比原序列大 那就是这个序列
否则把前m个数+1 【可能要进位】 然后再循环到n

特别的是 如果原序列为m个9 ,那就要循环到n+1

#include
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#define ls k<<1,l,mid
#define rs k<<1|1,mid+1,r
#define r(x) read(x)
#define rrr(x, y, z) read(x);read(y);read(z)
#define mp(x, y) make_pair(x,y)
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define FOR(i, l, r) for(int i=l;i<=r;i++)
using namespace std;

const int N = 1e5 + 5;
const int M = 1e3 + 5;
const int mod = 1e9 + 7;
const int INF = 0x7fffffff;
const int SZ = 17;
const double eps = 1e-8;
const double PI = acos(-1);
typedef long long LL;
typedef pair<int, int> pt;

int n, m;
char s1[N << 1], s2[N << 1];

template<class T>
inline void read(T &x) {
    char c;
    x = 1;
    while ((c = getchar()) < '0' || c > '9') if (c == '-') x = -1;
    T res = c - '0';
    while ((c = getchar()) >= '0' && c <= '9') res = res * 10 + c - '0';
    x *= res;
}

int main() {
    r(n);
    r(m);
    scanf("%s", s1 + 1);
    for (int i = 1; i <= n; i++) {
        s2[i] = s1[(i - 1) % m + 1];
    }
    bool flag = 1;
    for (int i = 1; i <= n; i++) {
        if (s2[i] > s1[i]) {
            break;
        } else if (s2[i] < s1[i]) {
            flag = 0;
            break;
        }
    }
    if (!flag) {
        bool f9 = 1;
        for (int i = 1; i <= m; i++) {
            if (s1[i] != '9') {
                f9 = 0;
                break;
            }
        }
        if (f9) {
            cout<<n+1<<endl;
            s1[1] = '1';
            for (int i = 2; i <= m; i++) {
                s1[i] = '0';
            }
            for (int i = 1; i <= n + 1; i++) {
                cout << s1[(i - 1) % m + 1];
            }
            cout << endl;
            return 0;
        }
        for (int i = m; i >= 1; i--) {
            if (s1[i] == '9') {
                s1[i] = '0';
            } else {
                s1[i]++;
                break;
            }
        }
        for (int i = 1; i <= n + 1; i++) {
            s2[i]=s1[(i - 1) % m + 1];
        }
    }
    cout<<n<<endl;
    for (int i = 1; i <= n; i++) {
        cout<<s2[i];
    }
    cout<<endl;
    return 0;
}

1269D - Domino for Young

这题代码比上一题短多了…
我就是找到了一个规律, 如果两个相邻的奇数之间的偶数的个数为偶数的话 那么这两个奇数列以及之间的都可以铺满
最后就 变成了找奇数列的序号是 奇数和偶数的个数 取最小值 然后加上所有数/2 的和
因为奇数和奇数之间 或 偶数和偶数之间 一定有奇数个 偶数列 ,所以每次配对都是在 奇数 和 偶数中各找一个列

#include
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#define ls k<<1,l,mid
#define rs k<<1|1,mid+1,r
#define r(x) read(x)
#define rrr(x, y, z) read(x);read(y);read(z)
#define mp(x, y) make_pair(x,y)
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define FOR(i, l, r) for(int i=l;i<=r;i++)
using namespace std;

const int N = 1e5 + 5;
const int M = 1e3 + 5;
const int mod = 1e9 + 7;
const int INF = 0x7fffffff;
const int SZ = 17;
const double eps = 1e-8;
const double PI = acos(-1);
typedef long long LL;
typedef pair<int, int> pt;

int n, m;
template<class T>
inline void read(T &x) {
    char c;
    x = 1;
    while ((c = getchar()) < '0' || c > '9') if (c == '-') x = -1;
    T res = c - '0';
    while ((c = getchar()) >= '0' && c <= '9') res = res * 10 + c - '0';
    x *= res;
}

int main() {
    r(n);
    LL ans1=0,ans2=0;
    FOR(i,1,n){
        int a; r(a);
        ans1+=a/2;
        ans2+=a/2;
        if(a&1){
            if(i&1) ans1++;
            else ans2++;
        }
    }
    cout<<min(ans1,ans2)<<endl;
    return 0;
}

你可能感兴趣的:(Contests)