ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Codeforces Round #662 (Div. 2)

2020-08-13 13:31:49  阅读:297  来源: 互联网

标签:题意 int Codeforces cin 662 正方形 木棒 https Div


目录

Codeforces Round #662 (Div. 2)

A. Rainbow Dash, Fluttershy and Chess Coloring

题意: 给一个正方形区域上色,类似于国际象棋:给两种颜色,要求相邻块的颜色不能相同。上色顺序是必须在一个已上色的相邻块上或者边界上上色。求最少上色几次可以完成全部上色?
题解: 画了画,猜的结论
代码:

#include <bits/stdc++.h>

using namespace std;

int n, t;

int main() {
    cin >> t;
    while (t--) {
        cin >> n;
        cout << n / 2 + 1 << endl;
    }
    return 0;
}

B. Applejack and Storages

题意: 题意为是我们一开始用n根各种长度的木棒,经过q次增加一根或减少某根长度的木棒,问在每次增减操作后能否用这些木棒构造出一个长方形和正方形,构造的时候只需要用这些木棒构成长方形和正方形的周长部分即可,并且每条边只能放一根木棒.
题解: 维护长方形和正方形的数目,x维护正方形的数目,y维护减去正方形的数目后长条可以两两配对的数目,然后模拟维护即可
代码:

#include <bits/stdc++.h>

using namespace std;

int const N = 1e5 + 10;
int n, a[N], x, y, m;

int main() {
    cin >> n;
    for (int i = 1, t; i <= n; ++i) {
        scanf("%d", &t);
        a[t]++;
    }
    for (int i = 1; i <= N - 10; ++i) {
        x += a[i] / 4;
        y += a[i] % 4 / 2;
    }
    
    char op[2];
    cin >> m;
    for (int i = 1, t; i <= m; ++i) {
        scanf("%s", op);
        scanf("%d", &t);
        if (op[0] == '+') {
            ++a[t];
            if (a[t] % 4 == 0) x++, --y;
            else if (a[t] % 4 == 2) ++y;
        }
        else {
            --a[t];
            if (a[t] % 4 == 1) --y;
            else if (a[t] % 4 == 3) --x, ++y;
        }
        if (x && (x > 1 || y >= 2)) cout << "YES\n";
        else cout << "NO\n";
    }
    return 0;
}

C. Pinkie Pie Eats Patty-cakes

题意: 给你n个数字,现在你需要将这些数字按照一定顺序排列后,使得数值相等的数字之间的间距的最小值最大。
题解: 比赛的时候写了个假二分,卡了一个小时,现在回头想想,二分里面的check函数没法写。但是实际上这道题直接贪心结论O(n)即可。
以这组数据为例:
14
1 1 1 2 2 2 3 3 3 4 4 6 7 8
把出现最多的数字分别尽可能摊开,然后中间的空隙填补其他的数字,具体见: https://blog.csdn.net/StandNotAlone/article/details/107873256
最终结果为:1,2,3, 4,6,8 1,2,3, 4,7, 1,2,3
代码:

#include <bits/stdc++.h>

using namespace std;

int const N = 2e5 + 10;
int T, n, a[N], cnt[N];

int main() {
    cin >> T;
    while (T--) {
        memset(cnt, 0, sizeof cnt);
        cin >> n;
        for (int i = 1; i <= n; ++i) scanf("%d", &a[i]), cnt[a[i]]++;
        int maxv_cnt = -1;
        for (int i = 1; i <= n; ++i) maxv_cnt = max(maxv_cnt, cnt[i]);
        vector<int> num;
        for (int i = 1; i <= n; ++i) if (cnt[i] == maxv_cnt) num.push_back(i);
        // int maxv_num_cnt = num.size();
        cout << num.size() - 1 + (n - maxv_cnt * num.size()) / (maxv_cnt - 1) << endl;
    }
    return 0;
}

// 3
// 2
// 0
// 4

参考:

  1. https://www.cnblogs.com/2aptx4869/p/13456091.html
  2. https://blog.csdn.net/StandNotAlone/article/details/107873256
  3. https://www.cnblogs.com/sszz/p/13456556.html

标签:题意,int,Codeforces,cin,662,正方形,木棒,https,Div
来源: https://www.cnblogs.com/spciay/p/13495881.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有