「解题报告」Codeforces Round 886 (Div. 4)
比赛地址:Dashboard - Codeforces Round 886 (Div. 4) - Codeforces
由于时间太晚了,因此并没有参加比赛,题目都是后来补做的。
A. To My Critics#
组数据,有 三个数,判断是否存在两个数的和 。
/*
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#
组数据,有 个人,每个人有一个反应,第 个人的反应长度为 ,质量为 。现在求出长度小于等于 的质量最高的人的编号。
/*
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#
有一个 的网格图,有一个单词在网格图中从上写到下,询问这个单词。
/*
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#
有 个数,还有一个整数 ,现在这 个数可以随便排序,也可以从这 个数中删去一些数,问最少删多少个数,可以使得剩下的数两两之间差的绝对值小于等于 。
转化一下,根据相邻两个数之间的差的绝对值大于 ,可以将这 个数分成若干段区间,求长度最大的区间,最后用 减去这个最大区间的长度即可。
/*
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#
有 个正方形,现在给每个正方形的边长加上 ,使得总面积为 ,求 。
一开始想的解方程,结果怎么着都避免不了爆 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#
暴力跳即可,相信看到这里的聪明的你一定可以看懂。
/*
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;
}
到此为止了。
作者:yifan0305
出处:https://www.cnblogs.com/yifan0305/p/17572944.html
版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。
转载时还请标明出处哟!
朝气蓬勃 后生可畏
分类:
解题报告
Buy me a cup of coffee ☕.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】