首页 > 其他分享 >2023.1.9(Educational Codeforces Round 141 & NEERC2017)

2023.1.9(Educational Codeforces Round 141 & NEERC2017)

时间:2023-01-10 14:36:37浏览次数:64  
标签:Educational cout 141 int lim cin Codeforces ++ tie

A.Yet Another Tournament

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

Statement

除了你以外有 \(n\) 个人,编号为 \(0 \to n - 1\) ,每个人有两个权值 \(a_i\) 和 \(b_i\),其中 \(a_i = i\) ,\(b_i\) 给定。现在你要同这 \(n\) 个人依据 \(a_i\) 的大小来排名(\(a_i\) 越大排名越靠前,你的排名等于 \(a_i\) 严格大于你的人的个数)。

你的 \(a_i\) 的大小等于 \(k\),且需要满足 \(b_{x_1} + b_{x_2} + \cdots + b_{x_k} \leq m\) (在 \(n\) 个人中选 \(k\) 个人,他们的 \(b_i\) 的和不大于一个给定的数 \(m\) ,此时的 \(k\) 就作为你的 \(a_i\) 的值)。

最小化你的最终排名。

Solution

假设你最终赢了 \(x\) 个人。不难发现 \(i < x\) 和 \(i > x\) 的人,无论你是否选择了他们,他们都不会影响你的最终排名。所以只有 \(i = x\) 的人会影响你的最终排名。那我们只需先最大化自己赢的人的个数,最终判断能否选第 \(x\) 个人即可。

Code

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

int T, n, m;

int main() {
    ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	freopen("in","r", stdin);
    cin >> T;
    while (T--) {
        cin >> n >> m;
        vector<int> a(n);
        for (auto &x : a) cin >> x;
        auto b = a;
        sort(b.begin(), b.end());
        int sum = 0, cnt = 0;
        for (auto x : b) {
            if (x + sum > m)
                break;
            sum += x;
            ++cnt;
        }
        if (cnt == 0) cout << n + 1 << endl;
        else if (cnt == n) cout << 1 << endl;
        else (sum + a[cnt] - b[cnt - 1] <= m) ? cout << n - cnt << endl : cout << n - cnt + 1 << endl;
    }
	return 0;
}

B.Consonant Fencity

https://codeforces.com/gym/101612/attachments/download/6287/20172018-acmicpc-neerc-northern-subregional-contest-en.pdf

Statement

定义以下集合:

\[U = \{ 'a' \to 'z' \} \\ S = \{ 'a', 'e', 'i', 'o', 'u', 'w', 'y' \} \\ T = \{ c \ | \ c \in U, c \notin S \} \]

给定字符串 \(s\), 函数 \(E(s)\) 等于「 \(s\) 中相邻字母均是 \(T\) 中的元素且大小写形式互不相同」的相邻对数。现在你可以改变任意字母在 \(s\) 中出现的大小写形式,但 \(s\) 中不同位置的本质相同的字母的形式均要相同,修改过后最终的字符串称作 \(s'\) 。最大化 \(E(s')\) 并输出 \(s'\) 。

Solution

考虑到 \(|T| = 19\),因此可以用一个二进制串来表示每一位(\(T\) 中每一种字母)的大小写形式,\(e.g. \ T_i = 1\) 表示大小,\(vice \ versa\).)

提前统计好 \(s\) 中出现过的 “\(T\) 元素对” 的个数,按题意统计即可。

Code

#include <bits/stdc++.h>
const int N = 100;
const char a[] = {'a', 'e', 'i', 'o', 'u', 'w', 'y'};
const char b[] = {'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'x', 'z'};
using namespace std;

string s;
bool con[N], vis[N];
int num[N][N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    freopen("consonant.in", "r", stdin);
    freopen("consonant.out", "w", stdout);
    cin >> s;
    for (int i = 0; i < 7; i++) con[a[i] - 'a'] = true;
    for (int i = 0; i < s.length() - 1; i++) {
        if (!(con[s[i] - 'a'] & con[s[i + 1] - 'a'])) {
            num[s[i] - 'a'][s[i + 1] - 'a']++;
            num[s[i + 1] - 'a'][s[i] - 'a']++;
        }
    }
    int ans = 0, maxx = 0;
    for (int sta = 0; sta < (1 << 19); sta++) {
        int res = 0;
        for (int i = 0; i < 19; i++) {
            if ((sta >> i) & 1) {
                for (int j = 0; j < 19; j++) {
                    if (!((sta >> j) & 1)) res += num[b[i] - 'a'][b[j] - 'a'];
                }
            }
        }
        if (res > maxx) {
            maxx = res;
            ans = sta;
        }
    }
    for (int i = 0; i < 19; i++) vis[b[i] - 'a'] = ((ans >> i) & 1);
    for (int i = 0; i < s.length(); i++) vis[s[i] - 'a'] ? cout << (char)toupper(s[i]) : cout << s[i];
	return 0;
}

C.Intelligence in Perpendicularia

https://codeforces.com/gym/101612/attachments/download/6287/20172018-acmicpc-neerc-northern-subregional-contest-en.pdf

Statement

在一个平面直角坐标系中 \((-10 ^ 6 \leq x, y \leq 10 ^ 6)\) 描绘一个封闭图形,该图形的每条边均与 \(x\) 轴或 \(y\) 轴平行,现在沿 \(x\) 轴正、负方向,\(y\) 轴正、负方向(四个方向)“发射阳光”,问“照不到阳光”的线段的总长度。

pSm9qht.png

上图中答案为 6

Solution

由于坐标的范围不大,因此可以使用坐标的值当作下标,记录每个 \(x\) 或 \(y\) 经过的次数,不难发现只有经过次数大于 \(2\) 的线段才“照不到阳光”,且可以随着经过次数的增大被重复统计。

整个过程用差分的思想即可,即分别对 \(x\) 和 \(y\) 进行差分,最终统计累加即可。

Code

#include <bits/stdc++.h>
const int lim = 1e6 + 1;
typedef long long ll;
using namespace std;

int n, x[lim + 5], y[lim + 5];
ll dx[2 * lim + 5], dy[2 * lim + 5];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    freopen("intel.in", "r", stdin);
    freopen("intel.out", "w", stdout);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> x[i] >> y[i];
        x[i] += lim;
        y[i] += lim;
    }
    x[n + 1] = x[1], y[n + 1] = y[1];
    for (int i = 2; i <= n + 1; i++) {
        if (x[i] == x[i - 1]) {
            int sy = min(y[i], y[i - 1]), ey = max(y[i], y[i - 1]);
            dy[sy]++;
            dy[ey]--;
        }
        else {
            int sx = min(x[i], x[i - 1]), ex = max(x[i], x[i - 1]);
            dx[sx]++;
            dx[ex]--;
        }
    }
    ll ans = 0;
    for (int i = 1; i <= lim * 2 - 1; i++) {
        dx[i] += dx[i - 1];
        dy[i] += dy[i - 1];
        ans += max(0ll, dx[i] - 2);
        ans += max(0ll, dy[i] - 2);
    }
    cout << ans << endl;
    return 0;
}

标签:Educational,cout,141,int,lim,cin,Codeforces,++,tie
From: https://www.cnblogs.com/BeyondLimits/p/17040188.html

相关文章

  • Codeforces Round #645 (Div. 2) A-D
    A.ParkLighting题意:用1*2的方格去填充n*m的格子,可以重叠摆放,至少需要多少个分析:不重叠的情况下,横着摆与竖着摆的最少数量是一样的,贡献为\(\lfloor\frac{n......
  • Codeforces 1704 F Colouring Game 题解 (结论,SG函数)
    题目链接首先看R和B的数量不等的情况(很多博弈题都是先比较两种物品的数量,相等的情况再用SG函数之类的技巧),结论是R多Alice必赢,B多Bob必赢。证明:来看R比B多的情况,定义两人......
  • Educational Codeforces Round 114 D(搜索剪枝)
    D.TheStrongestBuild题目大意:给定n个位置,每个位置有c\({_i}\)个可选能力值(能力值升序给出即a\({_1}\)<a\({_2}\)<a\({_3}\)<...<a\({_{ci}}\)),你可以在每个......
  • CodeForces - 510C Fox And Names
    CodeForces-510CFoxAndNames题解:建图+拓扑排序首先题目想让你按照给定的字符串修改字母表的字母序,我们很容易想到拓扑排序,但是这怎么建图?实际上对于两个输入的字......
  • Educational Codeforces Round 141 (Rated for Div. 2) Different Arrays
    Problem-D-Codeforces题意:给一个长度为n的数组a,下标从2到n-1,每个位置执行一次操作操作:设操作位置为i,$a_{i-1}+=a_i,a_{i+1}-=a_i$,或者$a_{i-1}-=a_i,a_......
  • Educational Codeforces Round 141 (Rated for Div. 2) A-E
    比赛链接A题意给一个数组\(a\),要求重排列以后\(a[i]\neqa[1,i-1]\),其中\(a[1,i-1]\)是前\(i-1\)项和。如果无解则输出NO;否则,给出一个合法的重排列后的\(a......
  • leetcode简单:[66, 67, 70, 83, 121, 141, 160, 169, ,206, 338]
    目录66.加一67.二进制求和70.爬楼梯83.删除排序链表中的重复元素121.买卖股票的最佳时机141.环形链表160.相交链表169.多数元素206.反转链表338.比特位计数66.......
  • 「Codeforces」寒假训练 2023 #3
    A.StringLCM原题链接#include<bits/stdc++.h>usingnamespacestd;typedeflonglongll;constintN=1e5+10;intq;strings,t;intlens,lent;int_lcm;......
  • Codeforces Round #266 (Div. 2) C. Number of Ways (dp)
    https://codeforces.com/contest/466/problem/C题目大意:数组a由n个整数组成a[1],a[2],...,a[n]。计算将数组中的所有元素分成三个连续部分的方法,以使每个部分中的元素总和......
  • Educational Codeforces Round 141 (Rated for Div. 2) A-C题解
    比赛链接A、MakeitBeautiful一种构造方法:按照从大到小的顺序构造,可以发现前缀和永远大于当前值。但是需要特判存在两个最大值的情况。只需要将最小值与第二位交换位置......