又是隔了一年才来补题的我

A、B水题就不用说了

C - Yet Another Walking Robot

C题我居然卡了一会,最后决定用map水,结果出来看了看题解,居然真的是map...没想到会出这样题解用stl的方法,是我失策了

#include <cstdio>
#include <algorithm>
#include <map>
using namespace std;
const int N = * ;
char s[N];
typedef pair <int, int> p;
map <p, int> k;
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
scanf("%s", s);
k.clear();
int c1 = , c2 = ;
int ans2 = 0x3f3f3f3f, ans1 = ;
k[make_pair(, )] = ;
for (int i = ; i < n; i++) {
if (s[i] == 'L') c1--;
else if (s[i] == 'R') c1++;
else if (s[i] == 'U') c2++;
else c2--;
if (k.find(make_pair(c1, c2)) == k.end()) {
k[make_pair(c1, c2)] = i + ;
continue;
}
int z = k[make_pair(c1, c2)];
if (i - z < ans2 - ans1)
ans2 = i + , ans1 = z + ;
k[make_pair(c1, c2)] = i + ;
}
if (ans1 == )
puts("-1");
else
printf("%d %d\n", ans1, ans2);
}
return ;
}
//LRUD
// 6 LLLLUUURRRRDDDLL
// LLLLLLUUURRDDDL

D - Fight with Monsters

比较水,先处理出一定能杀死的,把最后一轮剩下的丢尽一个优先队列里(直接排序也行),从小到大判断要用几次秘密武器才能打怪成功,注意要判断优先队列是不是非空(不然就会TLE一次...

#include <cstdio>
#include <queue>
#include <algorithm>
using namespace std;
int hp[ * ];
priority_queue < int, vector < int >, greater < int > > Q;
int main() {
int n, a, b, k, ans = ;
scanf("%d %d %d %d", &n, &a, &b, &k);
for (int i = ; i < n; i++) {
scanf("%d", &hp[i]);
if (hp[i] % (a + b) == )
Q.push(b);
else {
int res = hp[i] % (a + b);
if (res <= a)
ans++;
else
Q.push(res - a);
}
}
while (k > && !Q.empty()) { //就是这里
int u = Q.top(); Q.pop();
int cnt = u / a;
if (u % a != ) cnt++;
if (cnt > k)
break;
else
ans++, k -= cnt;
}
printf("%d", ans);
return ;
}

E1 - String Coloring (easy version)

题解是贪心或者dp,而我是二分图染色(迷惑行为),主要还是没看出来本质是划分子集,所以用二分图水过了,简单说一下题解做法吧,因为两个字母不按照字母顺序就要交换,所以如果把每个编号的视为一组,那么同组就是递增的,反之也是一样,如果能划分成两个上升的子序列,那一定可以按题目方式染色,因为你可以把不同颜色的字母随意改变顺序。还有一个方法是贪心,这个方法很有意思,目前有两个序列,判断当前这个能不能加在1后面,如果不行,能不能加在2后面,都不行就不能划分了,这种贪心方式的正确性在于,首先新的字母,无论加在序列1还是2后面产生的效果都是最后一个变成了s[i],由于先考虑序列1后考虑序列2,所以序列二的结尾总是小于序列1的,所以先加在1后面能保证序列二结尾尽可能的小,从而保证了贪心的正确性。

#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
char s[];
vector < int > e[];
int col[];
inline void add(int a, int b) {
e[a].push_back(b);
e[b].push_back(a);
}
int ans = ;
void dfs(int a, int c) {
col[a] = c;
for (int i = ; i < e[a].size(); i++) {
int u = e[a][i];
if (col[u] == -)
dfs(u, (c + ) % );
else if (col[u] == col[a]) {
ans = -;
return ;
}
}
} int main() {
int n;
scanf("%d", &n);
scanf("%s", s);
memset(col, 0xff, sizeof(col));
for (int i = ; i < n; i++)
for (int j = i + ; j < n; j++)
if (s[i] > s[j])
add(i, j);
for (int i = ; i < n; i++)
if (col[i] == -)
dfs(i, );
if (ans == -)
puts("NO");
else {
puts("YES");
for (int i = ; i < n; i++)
printf("%d", col[i]);
}
return ;
}

E2 - String Coloring (hard version)

下面这道题也很有意思,我刚做完的牛客比赛里正好有类似的题...有了easy版的推论,我们能看出就是最少分成几个不下降子序列,那就应用Dilworth定理,链划分的最少集合数等于最长反链长度,翻译成人话就是算最长下降子序列,这个nlogn的方法应该都知道,所以麻烦之处就在于划分,但是我们可以发现对于第i个字母s[i],以s[i]结尾的最长下降子序列长度就是它在的集合,首先相同长度一定是不下降的子序列,再者,对于s[i]而言,无法加到以大于s[i]结尾的序列后面,所以就只能成为一个新的序列。

#include <cstdio>
#include <algorithm>
using namespace std;
const int N = * 1e5 + ;
char s[N];
int dp[N], ans[N];
inline bool cmp(int a, int b) {
return a > b;
}
int main() {
int n;
scanf("%d", &n);
scanf("%s", s);
int len = ;
dp[] = s[] - 'a';
ans[] = ;
for (int i = ; i < n; i++) {
if (s[i] - 'a' < dp[len]) {
dp[++len] = s[i] - 'a';
ans[i] = len;
}
else {
int pos = lower_bound(dp + , dp + len + , s[i] - 'a', cmp) - dp;
ans[i] = pos;
dp[pos] = s[i] - 'a';
}
}
printf("%d\n", len);
for (int i = ; i < n; i++)
printf("%d ", ans[i]);
return ;
}

Codeforces Round #617 (Div. 3) 题解的更多相关文章

  1. Codeforces Round #182 (Div. 1)题解【ABCD】

    Codeforces Round #182 (Div. 1)题解 A题:Yaroslav and Sequence1 题意: 给你\(2*n+1\)个元素,你每次可以进行无数种操作,每次操作必须选择其 ...

  2. Codeforces Round #608 (Div. 2) 题解

    目录 Codeforces Round #608 (Div. 2) 题解 前言 A. Suits 题意 做法 程序 B. Blocks 题意 做法 程序 C. Shawarma Tent 题意 做法 ...

  3. Codeforces Round #525 (Div. 2)题解

    Codeforces Round #525 (Div. 2)题解 题解 CF1088A [Ehab and another construction problem] 依据题意枚举即可 # inclu ...

  4. Codeforces Round #528 (Div. 2)题解

    Codeforces Round #528 (Div. 2)题解 A. Right-Left Cipher 很明显这道题按题意逆序解码即可 Code: # include <bits/stdc+ ...

  5. Codeforces Round #466 (Div. 2) 题解940A 940B 940C 940D 940E 940F

    Codeforces Round #466 (Div. 2) 题解 A.Points on the line 题目大意: 给你一个数列,定义数列的权值为最大值减去最小值,问最少删除几个数,使得数列的权 ...

  6. Codeforces Round #677 (Div. 3) 题解

    Codeforces Round #677 (Div. 3) 题解 A. Boring Apartments 题目 题解 简单签到题,直接数,小于这个数的\(+10\). 代码 #include &l ...

  7. Codeforces Round #665 (Div. 2) 题解

    Codeforces Round #665 (Div. 2) 题解 写得有点晚了,估计都官方题解看完切掉了,没人看我的了qaq. 目录 Codeforces Round #665 (Div. 2) 题 ...

  8. Codeforces Round #160 (Div. 1) 题解【ABCD】

    Codeforces Round #160 (Div. 1) A - Maxim and Discounts 题意 给你n个折扣,m个物品,每个折扣都可以使用无限次,每次你使用第i个折扣的时候,你必须 ...

  9. Codeforces Round #383 (Div. 2) 题解【ABCDE】

    Codeforces Round #383 (Div. 2) A. Arpa's hard exam and Mehrdad's naive cheat 题意 求1378^n mod 10 题解 直接 ...

随机推荐

  1. 将jsp页面转化为图片或pdf(一)(qq:1324981084)

    java高级架构师全套vip教学视频,需要的加我qq1324981084 在项目中遇见了将jsp页面转化为pdf的问题,试过itext,但是itext需要标准的html代码,我的页面中的一些属性是it ...

  2. HTML连载70-相片墙、盒子阴影和文字阴影

    一. 制作一个相片墙 二. <!DOCTYPE html> <html lang="en"> <head> <meta charset=& ...

  3. Kotlin Tutorials系列文章

    Kotlin Tutorials系列文章 想写一个有实用价值的Kotlin笔记, 让一线开发一看就懂, 看完就能上手. 当然官方文档更有参考价值了. 这个系列相对于官方文档的大而全来说, 最主要优势是 ...

  4. 生成JavaDoc文档

    JavaDoc是一种将注释生成HTML文档的技术,生成的HTML文档类似于Java的API,易读且清晰明了.在简略介绍JavaDoc写法之后,再看一下在Intellij Idea 中如何将代码中的注释 ...

  5. 记录一个解决IOS极光推送解决问题方法的网址csdn

    https://blog.csdn.net/Three_Zhang/article/details/54667258

  6. vue富文本编辑器vue-quill-editor使用总结(包含图片上传,拖拽,放大和缩小)

    vue-quill-editor是vue很好的富文本编辑器,富文本的功能基本上都支持,样式是黑白色,简洁大方. 第一步下载 vue-quill-editor: npm i vue-quill-edit ...

  7. 阿里云K8S下玩.NET CORE 3.1

    1. 创建阿里云K8S集群,本文以标准托管集群为例 1.1 创建一个 2台 centos 2core 4G的 k8s 集群 1.2 创建成功的模样 2. 创建 asp.net core webapi项 ...

  8. javaSE学习笔记(16)---网络编程

    javaSE学习笔记(16)---网络编程 基本概念 如今,计算机已经成为人们学习.工作.生活必不可少的工具.我们利用计算机可以和亲朋好友网上聊天,也可以玩网游.发邮件等等,这些功能实现都离不开计算机 ...

  9. 一些实用的GitHub项目

    原文链接:http://www.louisvv.com/archives/2036.html 最近整理了一些在GitHub上比较热门的开源项目 关于GitHub,快速了解请戳这里 其中涵盖了:学习教程 ...

  10. win10创建本地用户

    win+r,输入lusrmgr.msc win+i