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

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. python网络爬虫(三)requests库的13个控制访问参数及简单案例

    酱酱~小编又来啦~

  2. 13.Android-ListView使用、BaseAdapter/ArrayAdapter/SimpleAdapter适配器使用

    1.ListView ListView 是 Android 系统为我们提供的一种列表显示的一种控件,使用它可以用来显示我们常见的列表形式.继承自抽象类 AdapterView.继承图如下所示: 以微信 ...

  3. win10安装两个不同版本的mysql(mysql5.7和mysql-8.0.19)

    win10中安装mysql5.7后,安装mysql-8.0.19 在D:\mysql-8.0.19-winx64目录下创建一个my.ini文件 [mysqld] # 设置3307端口 port # 设 ...

  4. Resnet——深度残差网络(二)

    基于上一篇resnet网络结构进行实战. 再来贴一下resnet的基本结构方便与代码进行对比 resnet的自定义类如下: import tensorflow as tf from tensorflo ...

  5. SpringCloud踩坑

    今天在使用 SpringCloud 时遇到了一个问题,感觉有不少小伙伴会遇到,所以记录下来 版本说明 SpringBoot 2.2.4.RELEASE SpringCloud Greenwich.SR ...

  6. 【56】目标检测之NMS非极大值抑制

    非极大值抑制(Non-max suppression) 到目前为止你们学到的对象检测中的一个问题是,你的算法可能对同一个对象做出多次检测,所以算法不是对某个对象检测出一次,而是检测出多次.非极大值抑制 ...

  7. js Dom为页面中的元素绑定键盘或鼠标事件

    html鼠标事件 onload 页面加载 onclick 鼠标单击 onmouseover 鼠标移入 onmouseout 鼠标移出 onfocus 获取焦点 onblur 失去焦点 onchange ...

  8. linux - 查看是否安装 JDK

    看看 是否设置了jdk环境变量: echo $JAVA_HOME: 或运行命令: java -verion 看看能否查看版本 ,能就是运行: 或者查看后台进程:ps -ef|grep java.

  9. 微信小程序后端开发流程

    微信小程序后端开发流程根据官网总结为两个步骤 1.前端调用 wx.login 返回了code,然后调用wx.getUserInfo获取到用户的昵称 头像 2.服务端根据code去微信获取openid, ...

  10. 将smarty安装到MVC架构中

    首先是composer.json { "require": { "smarty/smarty": "^3.1" }, // 自动加载 // ...