码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces Round #655 (Div. 2)

时间:2020-07-12 12:42:52      阅读:57      评论:0      收藏:0      [点我收藏+]

标签:条件判断   cout   lse   make   round   ace   cto   with   bit   

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 << ‘\n‘;
    }
    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 << ‘\n‘;
    }
    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 << ‘\n‘;
        else if (flag1 == 0 && flag3 == 0) cout << 1 << ‘\n‘;
        else if (flag2) cout << 1 << ‘\n‘;
        else cout << 2 << ‘\n‘;
    }
    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)

标签:条件判断   cout   lse   make   round   ace   cto   with   bit   

原文地址:https://www.cnblogs.com/2aptx4869/p/13287844.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!