Codeforces Round #699 (Div. 2)
A Space Navigation
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define RI register int
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int N = 2e5 + 20;
int n, m;
char s[N];
int main()
{
int __;
scanf("%d", &__);
while(__ -- )
{
scanf("%d%d", &n, &m);
scanf("%s", s);
int r = 0, u = 0, l = 0, d = 0;
int len = strlen(s);
for(int i = 0; i < len; ++ i)
{
if(s[i] == 'R') r ++;
if(s[i] == 'U') u ++;
if(s[i] == 'D') d ++;
if(s[i] == 'L') l ++;
}
int flag = 0;
if(n >= 0 && r < n) flag = 1;
if(n < 0 && l < abs(n)) flag = 1;
if(m >= 0 && u < m) flag = 1;
if(m < 0 && d < abs(m)) flag = 1;
if(flag) puts("NO");
else puts("YES");
}
return 0;
}
B New Colony
最多也就填充 \(10000\) 块,直接模拟即可,当滑出边界时 \(break\) 掉
#include <bits/stdc++.h>
using namespace std;
const int N = 100 + 10;
int n, k;
int h[N];
int main()
{
int __;
scanf("%d", &__);
while(__ -- )
{
scanf("%d%d", &n, &k);
for(int i = 1; i <= n; ++ i) scanf("%d", &h[i]);
int res;
bool flag = 0;
for(int i = 1; i <= k; ++ i)
{
flag = 1;
for(int j = 1; j < n; ++ j)
if(h[j] < h[j + 1])
{
flag = 0;
h[j] ++;
res = j;
break;
}
if(flag == 1) break;
}
if(flag) puts("-1");
else printf("%d\n", res);
}
return 0;
}
C Fence Painting
需要的颜色可以直接利用,不需要的颜色染到当前就是该颜色的位置或者接下来就要被染掉的位置
可以用队列暂存当前不需要的颜色,下次染色之前用掉
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 20;
int n, m;
int a[N], b[N], c[N];
int res[N];
map<int, vector<int>> mp;
map<int, vector<int>> hav;
bool check()
{
mp.clear(); hav.clear();
for(int i = 1; i <= n; ++ i)
if(a[i] != b[i]) mp[b[i]].push_back(i);
else hav[b[i]].push_back(i);
queue<int> q;
for(int i = 1; i <= m; ++ i)
{
if(!mp[c[i]].size())
{
if(!hav[c[i]].size()) q.push(i);
else
{
q.push(i);
while(!q.empty())
{
res[q.front()] = hav[c[i]].back();
q.pop();
}
}
}
else
{
while(!q.empty())
{
res[q.front()] = mp[c[i]].back();
q.pop();
}
res[i] = mp[c[i]].back();
a[res[i]] = c[i];
hav[c[i]].push_back(res[i]);
mp[c[i]].pop_back();
}
}
if(!q.empty()) return 0;
for(int i = 1; i <= n; ++ i)
if(a[i] != b[i]) return 0;
return 1;
}
int main()
{
int __;
scanf("%d", &__);
while(__ -- )
{
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]);
for(int i = 1; i <= m; ++ i) scanf("%d", &c[i]);
if(check())
{
puts("YES");
for(int i = 1; i <= m; ++ i) printf("%d ", res[i]);
puts("");
}
else puts("NO");
}
return 0;
}
D AB Graph
如果存在两个点之间的两条边上字母相同,一直在这两个点之间走即可
如果不存在上述情况,即任意两个点之间的两条边上字母不相同,则分奇偶讨论:
对于奇数的情况,任选两个点,在这两点之间一直走即可
对于偶数的情况,需要找到一个点 \(u\) 既有到 \(x\) 的字母 \(a\) 的出边, 也有到 \(y\) 的字母 \(b\) 的出边,在 \(u\) 和 \(x\) 之间走一半, 在 \(u\) 和 \(y\) 之间走一半即可
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define RI register int
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int N = 1e3 + 20;
int n, m;
char g[N][N];
void init()
{
for(int i = 1; i <= n; ++ i)
for(int j = i + 1; j <= n; ++ j)
if(g[i][j] == g[j][i])
{
puts("YES");
for(int k = 1; k <= m + 1; ++ k) printf("%d ", k % 2 ? i : j);
puts(""); return;
}
if(m % 2)
{
puts("YES");
for(int i = 1; i <= m + 1; ++ i) printf("%d ", i % 2 ? 1 : 2);
puts(""); return;
}
for(int i = 1; i <= n; ++ i)
{
int hav_a = 0, hav_b = 0;
for(int j = 1; j <= n; ++ j)
{
if(i == j) continue;
if(g[i][j] == 'a') hav_a = j;
if(g[i][j] == 'b') hav_b = j;
if(hav_a && hav_b) break;
}
if(!hav_a || !hav_b) continue;
puts("YES");
if(m % 4)
{
for(int j = 1; j <= m / 2 + 1; ++ j) printf("%d ", j % 2 ? hav_a : i);
for(int j = 1; j <= m / 2; ++ j) printf("%d ", j % 2 ? hav_b : i);
}
else
{
for(int j = 1; j <= m / 2 + 1; ++ j) printf("%d ", j % 2 ? i : hav_a);
for(int j = 1; j <= m / 2; ++ j) printf("%d ", j % 2 ? hav_b : i);
}
puts(""); return;
}
puts("NO");
return;
}
int main()
{
int __;
scanf("%d", &__);
while(__ -- )
{
scanf("%d%d", &n, &m); getchar();
for(int i = 1; i <= n; ++ i) scanf("%s", g[i] + 1);
init();
}
return 0;
}
E Sorting Books
考虑一种贪心策略,对于当前区间,应该尽量让出现次数较多的颜色保持不变,夹在中间的其他颜色后移.
设\(f[i]\) 为 \([i, n]\) 保持不变的书数量的最大值, 答案为 \(n - f[1]\)
状态转移为 f[i] = max(f[i + 1], f[i]), 若当前该种颜色还没全部出现,考虑维持该颜色不动是否更优
为了防止区间重叠,只有当一种颜色全部出现后再合并区间,即 \(f[i] = max(f[i], cnt[a[i]] + f[r[a[i] + 1])\)
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 20;
int n;
int a[N];
int f[N], cnt[N], l[N], r[N];
int main()
{
scanf("%d", &n);
for(int i = 1; i <= n; ++ i)
{
scanf("%d", &a[i]);
if(!l[a[i]]) l[a[i]] = i;
r[a[i]] = i;
}
for(int i = n; i >= 1; -- i)
{
f[i] = f[i + 1];
cnt[a[i]] ++;
if(l[a[i]] == i) f[i] = max(f[i], cnt[a[i]] + f[r[a[i]] + 1]);
else f[i] = max(f[i], cnt[a[i]]);
}
printf("%d\n", n - f[1]);
return 0;
}
Codeforces Round #699 (Div. 2)的更多相关文章
- 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后和给 ...
- Codeforces Round #268 (Div. 2) ABCD
CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...
随机推荐
- 一个方便 LeetCode 复习的脚本
这个脚本半年前就在用了,只不过一直没有公开. 这是一个简易的 LeetCode 自动统计程序, 可自动统计最近提交通过的题目, 并以 Markdown 的形式展示相关的数据. 采用 GitHub Ac ...
- linux环境下使用jmeter进行分布式测试
1.前言 熟练使用jmeter进行性能测试的工程师都知道,jmeter的客户端性能是有点差的.这会导致一个问题,其客户端的性能损耗会干扰到性能测试的结果,而且当线程数/并发大到一定程度时,客户端性能会 ...
- 国产网络损伤仪SandStorm -- 基本概念:什么是仿真引擎
"仿真引擎"在网络损伤仪SandStorm(www.minismb.com)或者网络IP仿真损伤仪中是一个最基本概念,它就相当于一个由两个物理以太网口组成的"网桥&quo ...
- Hexo之更换背景及透明度
Hexo之更换背景及透明度 引入方式 首先,介绍一下引入方式,外部导入css文件,不影响内部配置. 1.创建css文件 创建一个css文件移动到\themes\butterfly\source\css ...
- 1054D Changing Array 【位运算+思维】
题目:戳这里 题意:两个数n,k,满足给的n个数小于2的k次方.每个数可以进行一次操作,即把a[i]换成a[i]^(1<<k-1);求最多的连续区间数使得 区间[L,R] (1<=L ...
- C、C++语言中参数的压栈顺序
要回答这个问题,就不得不谈一谈printf()函数,printf函数的原型是:printf(const char* format,-) 没错,它是一个不定参函数,那么我们在实际使用中是怎么样知道它的参 ...
- 自己yy的中缀表达式转后缀表达式(未验证完全正确)
目前自己测试的表达式都没有出过问题 思路是这样,先将后缀表达式的计算顺序搞出来..当完全缩出来一个数的时候,如果后面还有要计算的,我们就把它放到后缀表达式的后面 先算后面的..不断迭代.. #incl ...
- 无需扫描即可查找和攻击域SQL Server (SPN)
无扫描SQL Server发现简介 当您没有凭据或正在寻找不在域中的SQL Server时,使用各种扫描技术来查找SQL Server可能非常有用.但是,此过程可能很嘈杂,耗时,并且可能由于子网未知, ...
- js spider
js spider https://gist.github.com/xgqfrms-GitHub/0bf82ff06037a0d1776c9f30033cbfd1 https://www.cnblog ...
- .gitignore规则不生效
.gitignore只能忽略那些原来没有被track的文件,如果某些文件已经被纳入了版本管理中,则修改.gitignore是无效的. 解决方法就是先把本地缓存删除(改变成未track状态),然后再提交 ...