Codeforces Round #655 (Div. 2)

Posted 2aptx4869

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #655 (Div. 2)相关的知识,希望对你有一定的参考价值。

unrated 呜呜呜

A

直接全输出1完事

#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=a;i<=(b);++i)
#define per(i,a,b) for(int i=a;i>=(b);--i)
#define IO ios::sync_with_stdio(0); cin.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef double db;
 
const int N = 1e5 + 5;
 
int n, m, _, k;
 
int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    for (cin >> _; _; --_) {
        cin >> n;
        rep (i, 1, n) cout << 1 << ‘ ‘;
         cout << ‘
‘;
    }
    return 0;
}

B

水水水, 数论氵题

#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=a;i<=(b);++i)
#define per(i,a,b) for(int i=a;i>=(b);--i)
#define IO ios::sync_with_stdio(0); cin.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef double db;
 
const int N = 1e5 + 5;
 
int n, m, _, k;
 
int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    for (cin >> _; _; --_) {
        cin >> n;
        int ans = n - 1, w = 1;
        for (int i = 2; (ll)i * i <= n; ++i)
            if (n % i == 0) {
                int c = (n / i + 1) >> 1;
                if (ans > (ll)c * i) w = i, ans = c * i;
                c = (n / (n / i) + 1) >> 1;
                if (ans > (ll)c * i) w = n / i, ans = c * i;
            }
 
        cout << w << ‘ ‘  << n - w << ‘
‘;
    }
    return 0;
}

C

条件判断, 看都题意就不难

直接拍好是 0

中间有一段 不和首尾相连的 一段啊a[i] == i, 2

其他的都是1

#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=a;i<=(b);++i)
#define per(i,a,b) for(int i=a;i>=(b);--i)
#define IO ios::sync_with_stdio(0); cin.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef double db;
 
const int N = 2e5 + 5;
 
int n, m, _, k;
int a[N];
 
int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    for (cin >> _; _; --_) {
        cin >> n;
        bool flag1 = 1, flag2 = 0, flag3 = 0;
        rep (i, 1, n) {
            cin >> a[i];
            if (flag1 == 1 && a[i] != i) flag1 = 0;
            else if (flag1 == 0 && a[i] == i && flag3 == 0) flag2 = 1, flag3 = 1;
            else if (flag2 == 1 && a[i] != i) flag2 = 0;
        }
 
        if (flag1 == 1) cout << 0 << ‘
‘;
        else if (flag1 == 0 && flag3 == 0) cout << 1 << ‘
‘;
        else if (flag2) cout << 1 << ‘
‘;
        else cout << 2 << ‘
‘;
    }
    return 0;
}

D

一开始写了个假算法, 小根堆写的, wa3

其实会发现, 对于每个数, 其相邻的两个数必定会合在一起, 只不过是合并顺序不同

导致每个数 加的次数 不同, 直接 O(n) 延长 找就行

#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=a;i<=(b);++i)
#define per(i,a,b) for(int i=a;i>=(b);--i)
#define IO ios::sync_with_stdio(0); cin.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef double db;
 
const int N = 2e5 + 5;
 
int n, m, _, k;
bool v[N];
int lf[N], rg[N];
ll a[N << 1], sum[N << 1];
 
int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    rep (i, 1, n) cin >> a[i], a[i + n] = a[i];

    sum[1] = a[1];
    rep (i, 2, n * 2) sum[i] = sum[i - 2] + a[i];

    ll ans = 0; 
    rep (i, n + 1, n * 2) ans = max(ans, sum[i] - sum[i - n - 1]);

    cout << ans;

    return 0;
}

E

应该是dp, 没想出来

以上是关于Codeforces Round #655 (Div. 2)的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #655 (Div. 2)

Codeforces Round #655 (Div. 2) A. Omkar and Completion

Codeforces Round #655 (Div. 2) D. Omkar and Circle

Codeforces Round #655 (Div. 2) A-D完

Codeforces Round #436 E. Fire(背包dp+输出路径)

[ACM]Codeforces Round #534 (Div. 2)