Codeforces Round #699 (Div. 2) A~C题解
写在前边
链接:Codeforces Round #699 (Div. 2)
好自闭哈哈,\(B\)题暴力fst了,第二天改了一个字母就A了,第3题写了一个小时,然后又调了三四个小时,看不到样例,最终放弃,不过看了官方代码后也大体知道哪错了,对于\(res[m]\)要单独算,不然会被覆盖的。
A Space Navigation
链接:A题链接
题目大意:
给定一个字符串,终点\((x, y)\),每个字母都表示向一个方向走一步,并且可以任意删除掉一些字母,问是否能从\((0, 0)\)走到终点\((x, y)\)
思路:
只需要根据字符串的操作,计算出在\(x\)轴或者\(y\)轴上活动的范围即可。
代码:
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <unordered_map>
using namespace std;
#define Inf 0x3f3f3f3f
#define PII pair<int, int>
#define P2LL pair<long long, long long>
#define endl '\n'
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<long long> VLL;
typedef vector<int> VI;
void solve() {
int x, y;
cin >> x >> y;
string s;
cin >> s;
int l = 0, u = 0, r = 0, d = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == 'L') l--;
else if (s[i] == 'U') u++;
else if (s[i] == 'R') r++;
else if (s[i] == 'D') d--;
}
if (x <= r && x >= l && y <= u && y >= d) puts("YES");
else puts("NO");
}
int main()
{
//ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
int t;
scanf("%d", &t);
while (t--) {
solve();
}
return 0;
}
B. New Colony
链接:B题链接
题目大意:
给定一组高度不一的山,从左边数第一座山滚石头,石头能第\(i\)坐山滚到第\(i+ 1\)座山的条件是,\(h_{i+1} <= h_{i}\),否则石头从第\(i\)座山落下,同时\(h_{i} += 1\),问最后一颗石头会落在第几座山,如果能完美通过每一座山那么输出\(-1\)
思路:
只接暴力模拟每一颗石头即可,一开始看到\(1e9\),就模拟了山脉,写的贼麻烦,今天发现,山最高才\(100\)。。。。
代码:
模拟山脉
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
#define Inf 0x3f3f3f3f
#define PII pair<int, int>
#define P2LL pair<long long, long long>
#define endl '\n'
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<long long> VLL;
typedef vector<int> VI;
const int N = 110;
int h[N], ch[N];
void solve() {
memset(h, 0, sizeof h);
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> h[i];
}
for (int i = 1; i < n; i++) {
while (h[i] < h[i + 1]) {
int max = h[i + 1];
for (int j = i; j >= 1; j--) {
int temp = h[j + 1] - h[j];
if (h[j] < h[j + 1]) {
if (h[j] + temp - h[j - 1] > 1 && j - 1 != 0) {
k -= (h[j - 1] + 1 - h[j]);
h[j] = h[j - 1] + 1;
}
else {
h[j] += temp;
k -= temp;
}
}
if (k <= 0) {
cout << j << endl;
return;
}
}
}
}
puts("-1");
}
int main()
{
//ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
int t;
scanf("%d", &t);
while (t--) {
solve();
}
system("pause");
return 0;
}
模拟石头
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
#define Inf 0x3f3f3f3f
#define PII pair<int, int>
#define P2LL pair<long long, long long>
#define endl '\n'
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<long long> VLL;
typedef vector<int> VI;
int h[110];
void solve() {
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> h[i];
}
int res = -1;
while (k) {
bool flag = false;
for (int i = 1; i <= n - 1; i++) {
if (h[i] < h[i + 1]) {
k--;
res = i;
h[i] += 1;
flag = true;
break;
}
}
if (!flag) {
cout << res << endl;
return;
}
}
puts("-1");
}
int main()
{
//ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
int t;
scanf("%d", &t);
while (t--) {
solve();
}
system("pause");
return 0;
}
C Fence Painting
链接:C题链接
题目大意:
工匠师傅给篱笆染色,并且工匠师傅有先后没人携带一种染色,无论如何不能拒绝他,即他一定会染一次色,问是现在的篱笆经过工匠师傅染色后是否能达到目标。
思路:
首先重要的一点是最后一个染色的师傅,假如他携带的颜色为\(c_m\),它可以给第\(k\)个位置的篱笆\(a_k\)染成\(b_k\),可以发现因为它是最后一个染色的,所以它可以覆盖原来第\(k\)个位置上的所有颜色,同时他还不会被改变因为他是最后一个,所以对于那些用不到的颜色我们可以通通涂到第\(k\)个位置,最后被最后一个染色师傅覆盖掉,剩下的就是代码实现了。
然后发现我们既需要存每个师傅可以染色的坐标,又要存一个颜色有多少个师傅携带,要实现这一点我们可以利用map<int, vector<int>>来存,或者vector<int> g[N],这里用中括号(不是圆括号)初始化的意义是有N个vector数组,用完一个师傅则\(pop_back()\)。
同时注意对于最后一个师傅可以涂的位置我们单独赋值,否则会在计算过程中被覆盖。
代码:
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <cstring>
using namespace std;
#define Inf 0x3f3f3f3f
#define PII pair<int, int>
#define P2LL pair<long long, long long>
#define endl '\n'
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<long long> VLL;
typedef vector<int> VI;
const int N = 1e5 + 10;
int a[N], b[N], c[N];
int res[N];
int n, m;
void solve() {
map<int, VI> cnt;
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= n; i++) {
scanf("%d", &b[i]);
if (b[i] != a[i]) {
cnt[b[i]].push_back(i);
}
}
for (int i = 1; i <= m; i++) scanf("%d", &c[i]);
int last = -1;
if (cnt[c[m]].size()) {
last = cnt[c[m]].back();
cnt[c[m]].pop_back();
}
else {
for (int i = 1; i <= n; i++) { //记录最后一个工匠师傅可以染色的位置
if (b[i] == c[m]) {
last = i;
}
}
}
if (last == -1) {
puts("NO");
return;
}
res[m] = last;
for (int i = 1; i <= m - 1; i++) {
if (cnt[c[i]].size() == 0) {
res[i] = last;
}
else {
res[i] = cnt[c[i]].back();
cnt[c[i]].pop_back();
}
}
for (auto it : cnt) {
if (it.second.size()) {
puts("NO");
return;
}
}
puts("YES");
for (int i = 1; i <= m; i++) {
cout << res[i] << " ";
}
puts("");
}
int main()
{
//ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
int t;
scanf("%d", &t);
while (t--) {
solve();
}
return 0;
}
Codeforces Round #699 (Div. 2) A~C题解的更多相关文章
- Codeforces Round #612 (Div. 2) 前四题题解
这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...
- Codeforces Round #198 (Div. 2)A,B题解
Codeforces Round #198 (Div. 2) 昨天看到奋斗群的群赛,好奇的去做了一下, 大概花了3个小时Ak,我大概可以退役了吧 那下面来稍微总结一下 A. The Wall Iahu ...
- Codeforces Round #672 (Div. 2) A - C1题解
[Codeforces Round #672 (Div. 2) A - C1 ] 题目链接# A. Cubes Sorting 思路: " If Wheatley needs more th ...
- Codeforces Round #614 (Div. 2) A-E简要题解
链接:https://codeforces.com/contest/1293 A. ConneR and the A.R.C. Markland-N 题意:略 思路:上下枚举1000次扫一遍,比较一下 ...
- Codeforces Round #610 (Div. 2) A-E简要题解
contest链接: https://codeforces.com/contest/1282 A. Temporarily unavailable 题意: 给一个区间L,R通有网络,有个点x,在x+r ...
- Codeforces Round #611 (Div. 3) A-F简要题解
contest链接:https://codeforces.com/contest/1283 A. Minutes Before the New Year 题意:给一个当前时间,输出离第二天差多少分钟 ...
- Codeforces Round #499 (Div. 2) D. Rocket题解
题目: http://codeforces.com/contest/1011/problem/D This is an interactive problem. Natasha is going to ...
- Codeforces Round #499 (Div. 2) C Fly题解
题目 http://codeforces.com/contest/1011/problem/C Natasha is going to fly on a rocket to Mars and retu ...
- Codeforces Round #198 (Div. 2)C,D题解
接着是C,D的题解 C. Tourist Problem Iahub is a big fan of tourists. He wants to become a tourist himself, s ...
- Codeforces Round #579 (Div. 3) 套题 题解
A. Circle of Students 题目:https://codeforces.com/contest/1203/problem/A 题意:一堆人坐成一个环,问能否按逆时针或者顺时针 ...
随机推荐
- Pandas:获取Dataframe索引
解决方案 效果图 参考链接 https://blog.csdn.net/YENTERTAINR/article/details/109254583
- 这些年写过的花式sql - 第一句 删除重复无效的记录
这些年写过的花式sql - 第一句 删除重复无效的记录 写好复杂sql可以减少代码量,经过写这些年的后台统计,我学着像写代码一样的设计和尝试sql.现整理如下: 本来想一次性写完的,不过那写起来和看起 ...
- AcWing 第 92 场周赛 C题 4866. 最大数量 题解
原题链接 链表 + 并查集乱搞做法: 思路 首先可以发现,想要让度数尽量大,那我们应该构造成菊花图,即下图所示: 对于每个需求,我们可以知道,如果之前他们没有连在一起,那我们一定得把他们连在一起,该过 ...
- TIKZ全局样式设置
tikz绘图引擎 TIKZ绘图引擎是基于tex实现,代码极其复杂,每次编写都要单独设置样式,甚是繁琐,如何能够全局设置呢? \begin{tikzpicture}[ auto, % 决策结点 deci ...
- 拉普拉斯金字塔在多图HDR算法中的应用以及多曝光图像的融合算法简介。
在SSE图像算法优化系列二十九:基础的拉普拉斯金字塔融合用于改善图像增强中易出现的过增强问题(一) 一文中我们曾经描述过基于几种高频融合法则的拉普拉斯金字塔融合算法,那里是主要针对2副图像的.实际的应 ...
- numpy中矩阵的逆,求解,特征值,特征向量
逆:numpy.linalg.inv() # 求矩阵的逆import numpy as npa=np.mat('1 0;0 1')#生成一个矩阵print(type(a))b=np.linalg.in ...
- Java爬虫实战系列2——动手写爬虫初体验
在上面的章节中,我们介绍了几个目前比较活跃的Java爬虫框架.在今天的章节中,我们会参考开源爬虫框架,开发我们自己的Java爬虫软件. 首先,我们下载本章节要使用到的源代码,本章节主要提供了基于HTT ...
- webgl centroid质心插值的一点理解
质心插值说的是什么 2023.10.04再次review这个细节点: https://www.opengl.org/pipeline/article/vol003_6/ https://github. ...
- Go语言系列——21-Go协程、22-信道(channel)、23-缓冲信道和工作池、24-Select、25-Mutex、26-结构体取代类、27-组合取代继承、多态、 29-Defer、错误处理
文章目录 21-Go协程 Go 协程是什么? Go 协程相比于线程的优势 如何启动一个 Go 协程? 启动多个 Go 协程 22-信道(channel) 什么是信道? 信道的声明 通过信道进行发送和接 ...
- Python面向对象——Mixin机制、重载、多态与鸭子类型、绑定与非绑定方法、Python常见的内置函数
文章目录 内容回顾 Mixin机制 1.什么是Mixin 2.Mixin来源 3.定义及优点 4.在python中的应用 5.在Django项目中的应用 重载(在子类派生的新方法中如何重用父类的功能) ...