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后和给 ...
随机推荐
- FastApi 进阶
前言 终于有了第一个使用 FastApi 编写的线上服务, 在开发的过程中还是遇到了些问题, 这里记录一下 正文 目录结构 我们知道, FastApi 的启动方式推荐使用 uvicorn, 其启动方式 ...
- 剑指offer 面试题9.1:用两个队列实现栈
题目描述 使用队列实现栈的下列操作:push(x) -- 元素 x 入栈:pop() -- 移除栈顶元素:top() -- 获取栈顶元素:empty() -- 返回栈是否为空: 编程思想 利用双队列实 ...
- CPNDet:粗暴地给CenterNet加入two-stage精调,更快更强 | ECCV 2020
本文为CenterNet作者发表的,论文提出anchor-free/two-stage目标检测算法CPN,使用关键点提取候选框再使用两阶段分类器进行预测.论文整体思路很简单,但CPN的准确率和推理速度 ...
- xtrabackup迁移mysql5.7.32
问题描述:利用外部xtrabackup工具来做迁移mysql数据库,或者恢复数据库 xtrabackup迁移mysql 1.环境 mysql源库 mysql目标迁移库 IP 192.168.163.3 ...
- 【Java】计算机软件、博客的重要性、编程语言介绍和发展史
之前学得不踏实,重新复习一遍,打扎实基础中. 记录 Java核心技术-宋红康_2019版 & Java零基础学习-秦疆 文章目录 软件开发介绍 软件开发 什么是计算机? 硬件及冯诺依曼结构 计 ...
- 【Linux】查看系统僵尸进程
ps -ef|grep -v grep|grep defunct 如果这个有显示内容的话,可以手动将进程kill掉即可 ---------------------------------------- ...
- LeetCode563. 二叉树的坡度
题目 1 class Solution { 2 public: 3 int ans = 0; 4 int findTilt(TreeNode* root) { 5 postOrder(root); 6 ...
- RWCTF2020 DBaaSadge 复现
数据库题目 2020RWCTF DBaaSadge WP 这是一个很有意思的题目,难到让我绝望,跟着大佬smity的思路跑一下,求大佬抱抱. https://mp.weixin.qq.com/s/jv ...
- WTM5.0发布,全面支持.net5
WTM5.0是WTM框架开源2年以来最大的一次升级,全面支持.net5,大幅重构了底层代码,针对广大用户提出的封装过度,不够灵活,性能不高等问题进行了彻底的修改. 这次升级使WTM继续保持开箱即用,高 ...
- [Usaco2008 Feb]Line连线游戏
题目描述 Farmer John最近发明了一个游戏,来考验自命不凡的贝茜.游戏开始的时 候,FJ会给贝茜一块画着N (2 <= N <= 200)个不重合的点的木板,其中第i个点 的横.纵 ...