Loading

「解题报告」Codeforces Round 886 (Div. 4)

比赛地址:Dashboard - Codeforces Round 886 (Div. 4) - Codeforces

由于时间太晚了,因此并没有参加比赛,题目都是后来补做的。

A. To My Critics

Problem - A - Codeforces

\(T\) 组数据,有 \(a, b, c\) 三个数,判断是否存在两个数的和 \(sum \ge 10\)

/*
  The code was written by yifan, and yifan is neutral!!!
 */

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

template<typename T>
inline T read() {
    T x = 0;
    bool fg = 0;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        fg |= (ch == '-');
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = (x << 3) + (x << 1) + (ch ^ 48);
        ch = getchar();
    }
    return fg ? ~x + 1 : x;
}

void solve() {
    int a = read<int>(), b = read<int>(), c = read<int>();
    if (a + b >= 10 || b + c >= 10 || a + c >= 10) {
        puts("Yes");
    } else {
        puts("No");
    }
}

int main() {
    int T = read<int>();
    while (T --) {
        solve();
    }
    return 0;
}

B. Ten Words of Wisdom

Problem - B - Codeforces

\(T\) 组数据,有 \(n\) 个人,每个人有一个反应,第 \(i\) 个人的反应长度为 \(a_i\),质量为 \(b_i\)。现在求出长度小于等于 \(10\) 的质量最高的人的编号。

/*
  The code was written by yifan, and yifan is neutral!!!
 */

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

template<typename T>
inline T read() {
    T x = 0;
    bool fg = 0;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        fg |= (ch == '-');
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = (x << 3) + (x << 1) + (ch ^ 48);
        ch = getchar();
    }
    return fg ? ~x + 1 : x;
}

int n, a, b;

void solve() {
    n = read<int>();
    int mx = 0, pos = 0;
    for (int i = 1; i <= n; ++ i) {
        a = read<int>(), b = read<int>();
        if (a <= 10) {
            if (b > mx) {
                mx = b;
                pos = i;
            }
        }
    }
    cout << pos << '\n';
}

int main() {
    int T = read<int>();
    while (T --) {
        solve();
    }
    return 0;
}

C. Word on the Paper

Problem - C - Codeforces

有一个 \(8 \times 8\) 的网格图,有一个单词在网格图中从上写到下,询问这个单词。

/*
  The code was written by yifan, and yifan is neutral!!!
 */

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

template<typename T>
inline T read() {
    T x = 0;
    bool fg = 0;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        fg |= (ch == '-');
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = (x << 3) + (x << 1) + (ch ^ 48);
        ch = getchar();
    }
    return fg ? ~x + 1 : x;
}

char c;
char str[10];

void solve() {
    memset(str, '\0', sizeof str);
    int l = 0;
    for (int i = 1; i <= 8; ++ i) {
        for (int j = 1; j <= 8; ++ j) {
            cin >> c;
            if (c >= 'a' && c <= 'z') {
                str[l ++] = c;
            }
        }
    }
    cout << str << '\n';
}

int main() {
    int T = read<int>();
    while (T --) {
        solve();
    }
    return 0;
}

D. Balanced Round

Problem - D - Codeforces

\(n\) 个数,还有一个整数 \(k\),现在这 \(n\) 个数可以随便排序,也可以从这 \(n\) 个数中删去一些数,问最少删多少个数,可以使得剩下的数两两之间差的绝对值小于等于 \(k\)

转化一下,根据相邻两个数之间的差的绝对值大于 \(k\),可以将这 \(n\) 个数分成若干段区间,求长度最大的区间,最后用 \(n\) 减去这个最大区间的长度即可。

/*
  The code was written by yifan, and yifan is neutral!!!
 */

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

template<typename T>
inline T read() {
    T x = 0;
    bool fg = 0;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        fg |= (ch == '-');
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = (x << 3) + (x << 1) + (ch ^ 48);
        ch = getchar();
    }
    return fg ? ~x + 1 : x;
}

const int N = 2e5 + 5;

int n, k;
int g[N];
vector<int> pos;

void solve() {
    pos.clear();
    n = read<int>(), k = read<int>();
    for (int i = 1; i <= n; ++ i) {
        g[i] = read<int>();
    }
    sort(g + 1, g + n + 1);
    pos.emplace_back(1);
    for (int i = 2; i <= n; ++ i) {
        if (g[i] - g[i - 1] > k) {
            pos.emplace_back(i);
        }
    }
    pos.emplace_back(n + 1);
    int siz = pos.size(), mx = -1;
    for (int i = 1; i < siz; ++ i) {
        mx = max(mx, pos[i] - pos[i - 1]);
//        cout << pos[i] - pos[i - 1] << '\n';
    }
    cout << (mx == -1 ? n : n - mx) << '\n';
}

int main() {
    int T = read<int>();
    while (T --) {
        solve();
    }
    return 0;
}

E. Cardboard for Pictures

Problem - E - Codeforces

\(n\) 个正方形,现在给每个正方形的边长加上 \(2w\),使得总面积为 \(c\),求 \(w\)

一开始想的解方程,结果怎么着都避免不了爆 long long ,后来在旁边的大佬的提醒下用了二分。

/*
  The code was written by yifan, and yifan is neutral!!!
 */

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

template<typename T>
inline T read() {
    T x = 0;
    bool fg = 0;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        fg |= (ch == '-');
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = (x << 3) + (x << 1) + (ch ^ 48);
        ch = getchar();
    }
    return fg ? ~x + 1 : x;
}

const int N = 2e5 + 5;

int n;
ll c, sum;
ll d[N];

int check(ll w) {
    sum = 0;
    for (int i = 1; i <= n; ++ i) {
        sum += (d[i] + 2 * w) * (d[i] + 2 * w);
        if (sum > c)    return false;
    }
    return true ;
}

void solve() {
    n = read<int>(), c = read<ll>();
    for (int i = 1; i <= n; ++ i) {
        d[i] = read<ll>();
    }
    ll l = 1, r = 1e9, ans = 0;
    while (l <= r) {
        ll mid = (l + r) >> 1;
        if (check(mid)) {
            l = mid + 1;
            ans = mid;
        } else {
            r = mid - 1;
        }
    }
    cout << ans << '\n';
}

int main() {
    int T = read<int>();
    while (T --) {
        solve();
    }
    return 0;
}

F. We Were Both Children

Problem - F - Codeforces

暴力跳即可,相信看到这里的聪明的你一定可以看懂。

/*
  The code was written by yifan, and yifan is neutral!!!
 */

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

template<typename T>
inline T read() {
	T x = 0;
	bool fg = 0;
	char ch = getchar();
	while (ch < '0' || ch > '9') {
		fg |= (ch == '-');
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9') {
		x = (x << 3) + (x << 1) + (ch ^ 48);
		ch = getchar();
	}
	return fg ? ~x + 1 : x;
}

const int N = 2e5 + 5;

int n;
int d[N], in[N];

void solve() {
	n = read<int>();
	for (int i = 1; i <= n; ++ i) {
		d[i] = in[i] = 0;
	}
	for (int i = 1, x; i <= n; ++ i) {
		x = read<int>();
		if (x <= n) {
			++ in[x];
		}
		d[i] = 0;
	}
	for (int i = 1; i <= n; ++ i) {
		for (int j = i; j <= n; j += i) {
			d[j] += in[i];
		}
	}
	cout << *max_element(d + 1, d + n + 1) << '\n';
}

int main() {
	int T = read<int>();
	while (T --) {
		solve();
	}
	return 0;
}

到此为止了。

posted @ 2023-07-22 10:26  yi_fan0305  阅读(70)  评论(0编辑  收藏  举报