Codeforces Round #637 (Div. 2)
比赛链接:https://codeforces.com/contest/1341
A - Nastya and Rice
题意
有 n 堆米,每堆质量在 [a-b,a+b] 之间,这些米的总质量是否可能在 [c-d,c+d] 之间。
思路
n 堆米的最小总质量为 n*(a-b),最大总质量为 n*(a+b),即判断区间 [n*(a-b),n*(a+b)] 是否与 [c-d,c+d] 相交。
代码
#include <bits/stdc++.h>
using namespace std; void solve() {
int n, a, b, c, d; cin >> n >> a >> b >> c >> d;
int mi = n * (a - b);
int mx = n * (a + b);
if (c + d < mi or c - d > mx)
cout << "No" << "\n";
else
cout << "Yes" << "\n";
} int main() {
int t; cin >> t;
while (t--) solve();
}
B - Nastya and Door
题意
有一数组 a,定长 k 最多能完整覆盖多少 a[i-1] < a[i] 且 a[i] > a[i+1] 的长为 3 的区间,不考虑数组两端。
思路一
前缀和记录每个端点为止的符合条件的区间数量,之后枚举定长的起始点,覆盖区间的右端点需要再减一来错峰。
代码一
#include <bits/stdc++.h>
using namespace std; void solve() {
int n, k; cin >> n >> k;
int a[n + 1]= {};
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int cnt[n + 1] = {};
for (int i = 1; i <= n; i++) {
cnt[i] += cnt[i - 1];
if (a[i] > a[i - 1] and a[i] > a[i + 1])
++cnt[i];
}
int mx = 1, st = 1;
for (int i = 1; i + k - 1 <= n; i++) {
int l = i, r = i + k - 2;
int sub = cnt[r] - cnt[l] + 1;
if (sub > mx) mx = sub, st = l;
}
cout << mx << ' ' << st << "\n";
} int main() {
int t; cin >> t;
while (t--) solve();
}
思路二
记录所有符合条件区间的左右端点,对于每个枚举的起始点二分查找最近的区间左右端点。
代码二
#include <bits/stdc++.h>
using namespace std; void solve() {
int n, k; cin >> n >> k;
int a[n + 1]; for (int i = 1; i <= n; i++) cin >> a[i];
vector<int> l, r;
for (int i = 2; i <= n - 1; i++) {
if (a[i - 1] < a[i] and a[i] > a[i + 1]) {
l.push_back(i - 1);
r.push_back(i + 1);
}
}
int mx = 1, st = 1;
for (int i = 1; i <= n; i++) {
int lf = lower_bound(l.begin(), l.end(), i) - l.begin();
int rt = upper_bound(r.begin(), r.end(), i + k - 1) - r.begin();
if (rt > 0 and rt - lf + 1 > mx) {
mx = rt - lf + 1;
st = i;
}
}
cout << mx << ' ' << st << "\n";
} int main() {
int t; cin >> t;
while (t--) solve();
}
C - Nastya and Strange Generator
题意
[1,2,3,...,n] 中每次可从一点起向右连续选取所有未选取的位置并依次放置 1 ~ n,问所有可能的放置中是否有当前排列。
思路
因为是连续放置的所以 a[i - 1] + 1 = a[i] 或 a[i - 1] > a[i],即 a[i] - a[i - 1] ≤ 1。
代码
#include <bits/stdc++.h>
using namespace std; void solve() {
int n; cin >> n;
int a[n]; for (int &i : a) cin >> i;
for (int i = 0; i + 1 < n; i++) {
if (a[i + 1] - a[i] > 1) {
cout << "No" << "\n";
return;
}
}
cout << "Yes" << "\n";
} int main() {
int t; cin >> t;
while (t--) solve();
}
D - Nastya and Scoreboard
题意
有一液晶数字板,其中亮着一些段,问再点亮 k 段所能构成的最大数字。
思路
先确定每位可以用掉几段,ok[i][j] 表示第 i 位可以用掉 j 段,之后从后向前构造,dp[i][j] 表示构造到第 i 位时用 j 段是否可行,dp[0][k] 可行即有解(构造 n-1 → 0 位)。因为在 dp 的过程中每一位每一种可行的情况都是与之后一系列的位相关联的,所以当输出第一位的最大可行数字后后面一系列的位就已经确定了。
代码
#include <bits/stdc++.h>
using namespace std; const int M = 2200; string str[10] = {"1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111011"};
int a[M], s[10];
bool ok[M][8], dp[M][M]; int main() {
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 7; j++) {
s[i] = 2 * s[i] + str[i][j] - '0';
}
}
int n, k; cin >> n >> k;
for (int i = 0; i < n; i++) {
int a_i = 0;
for (int j = 0; j < 7; j++) {
char c; cin >> c;
a_i = 2 * a_i + c - '0';
}
a[i] = a_i;
for (int j = 0; j < 10; j++) {
if ((a[i] & s[j]) == a[i]) {
int cnt = __builtin_popcount(a[i] ^ s[j]);
ok[i][cnt] = true;
}
}
}
dp[n][0] = true;
for (int i = n - 1; i >= 0; i--)
for (int j = 0; j < M; j++)
if (dp[i + 1][j])
for (int k = 0; k <= 7; k++)
if (ok[i][k])
dp[i][j + k] = true;
if (!dp[0][k]) cout << "-1";
else {
for (int i = 0; i < n; i++)
for (int j = 9; ; j--)
if ((a[i] & s[j]) == a[i]) {
int cnt = __builtin_popcount(a[i] ^ s[j]);
if (dp[i + 1][k - cnt]) {
k -= cnt; cout << j;
break;
}
}
}
}
Codeforces Round #637 (Div. 2)的更多相关文章
- Codeforces Round #637 (Div. 2) 题解
A. Nastya and Rice 网址:https://codeforces.com/contest/1341/problem/A Nastya just made a huge mistake ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
- Codeforces Round #262 (Div. 2) 1004
Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...
- Codeforces Round #371 (Div. 1)
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...
随机推荐
- 【.NET与树莓派】上手前的一些准备工作
.NET Iot 不是什么新鲜事物,百科很强大,故老周在此也不必多介绍.现在的时代和老周当年学 QBasic 的时代不同,那时候拉根电话线上网,下载速度只有可怜的 3.5 kb/s.而且还要去店里买上 ...
- git revert 回退已经push的内容
如题,在日常的开发过程中,可能有组员不小心一下子吧文件修改,需要进行回退 回退主要涉及到2种命令,一种是git reset 一种是 git revert git reset 会修改git log提交历 ...
- MySQL select 语句指定字段查询
指定字段查询 SELECT 语法 SELECT [ALL | DISTINCT] {* | table.* | [table.field1[as alias1][,table.field2[as al ...
- Kafka 探险 - 生产者源码分析: 核心组件
这个 Kafka 的专题,我会从系统整体架构,设计到代码落地.和大家一起杠源码,学技巧,涨知识.希望大家持续关注一起见证成长! 我相信:技术的道路,十年如一日!十年磨一剑! 往期文章 Kafka 探险 ...
- MySQL查询截取分析
一.查询优化 1,mysql的调优大纲 慢查询的开启并捕获 explain+慢SQL分析 show profile查询SQL在Mysql服务器里面的执行细节和生命周期情况 SQL数据库服务器的参数调优 ...
- os-hackos-3-docker提权
0x00 cewl http://192.168.43.179/websec/爬取页面所有的单词做成字典 hydra -l contact@hacknos.com -P cewl.txt 192.16 ...
- ALV中的fieldcat详解
字段目录是用来控制ALV显示的网格中每个字段的属性的,比如字段的顺序,对齐方式,可编辑状态,颜色,等等.常用的字段如下: Row_pos: 默认值为0,可选值为1.2.3,既最大分3级别显示 c ...
- QT串口助手(二):参数配置
作者:zzssdd2 E-mail:zzssdd2@foxmail.com 一.前言 主要实现功能 串口参数的配置:波特率.数据位.停止位.校验位 本机串口设备的查询与添加显示 串口设备的手动更新与打 ...
- kvm实战
1. 安装环境 # yum install qemu-kvm libvirt virt-install virt-manager virt-viewer -y # systemctl start li ...
- b站视频_下载_去水印_视频转mp4-批量下载神器
b站下载_视频_去水印_转mp4_批量下载的解决办法 以下问题均可解决 b站下载的视频如何保存到本地 b站下载的视频在那个文件夹里 b站下载视频转mp4 b站下载app b站下载在哪 b站下载视频电脑 ...