A. Diverse Substring

找普遍性(特殊解即可)。

最简单的便是存在一个区间\([i, i + 1] (1 <= i < n)\),且$str[i] $ $ != str[i + 1]$,就满足题意了。

对于其他的有可能满足的序列,必须存在:

这个字母的出现次数 $ <= $ 除这个字母之外的出现次数总和。

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int N = 1010;
int n;
char str[N];
int main(){
cin >> n >> (str + 1);
for(int i = 1; i < n; i++){
if(str[i] != str[i + 1]){
printf("YES\n%c%c\n", str[i], str[i + 1]);
return 0;
}
}
puts("NO");
return 0;
}

B. Vasya and Books

设 \(dep\) 为已知取出的层数,初始化为\(0\),\(cnt[i]\)代表i数字出现的位置

每次处理一个数字\(x\):

1、若$cnt[x] <= dep $,意味着这个数已经被清理了,直接输出\(0\)即可

2、否则,则将\(x - dep\)的数全部清理。

#include <iostream>
#include <cstdio>
using namespace std;
const int N = 200010;
int n, a[N]; int main(){
scanf("%d", &n);
for(int i = 1, x; i <= n; i++)
scanf("%d", &x), a[x] = i;
int dep = 0;
for(int i = 1; i <= n; i++){
int x; scanf("%d", &x);
if(a[x] <= dep) printf("0 ");
else printf("%d ", a[x] - dep), dep = a[x];
}
return 0;
}

C. Vasya and Robot

显然,如果修改长度为\(len\)可以成功,那么修改长度$ > len$的也都可以成功。

(可以让修改的那部分不变,剩下的照搬)

满足单调性,既可二分。

可以处理前缀和,来预处理除了\([l ,l + len - 1]\)区间外另外的部分走到的部分。

因为符合交换律(先走$[1, l - 1] 与 [l + len, n] \(的路径,再走\)[l ,l + len - 1]$ 结果不变),所以一次前缀和即可完成任务。

\(check()\)函数的书写需要注意,不单单需要曼哈顿距离(即从$(nx, ny) -> (tx, ty) \(的最短路径​ )\) >= len$,而且哈密尔路径的奇偶性必须和曼哈顿距离一样,否则无论怎样都到不了。

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int N = 200010;
int n, tx, ty, x[N], y[N];
char str[N];
bool inline check(int len){
for(int l = 1, r = len; r <= n; l++, r++){
int nx = x[n] - (x[r] - x[l - 1]);
int ny = y[n] - (y[r] - y[l - 1]);
int dist = abs(tx - nx) + abs(ty - ny);
if(len >= dist && (dist & 1) == (len & 1)) return true;
}
return false;
}
int main(){
scanf("%d%s%d%d", &n, str + 1, &tx, &ty);
for(int i = 1; i <= n; i++){
x[i] = x[i - 1], y[i] = y[i - 1];
if(str[i] == 'U') y[i]++;
else if(str[i] == 'D') y[i]--;
else if(str[i] == 'L') x[i]--;
else if(str[i] == 'R') x[i]++;
}
if(!check(n)) puts("-1");
else{
int l = 0, r = n;
while(l < r){
int mid = (l + r) >> 1;
if(check(mid)) r = mid;
else l = mid + 1;
}
printf("%d", r);
} return 0;
}

D. Berland Fair

可以预处理每次\(m\)对应的买的糖果,对其取模,因为这几次的行为是相同的,可以加快速度。

存在两数\(a\)、\(b\)且吗满足\(a >= b\),则一定满足$a % b <= a / 2 $。

#include <iostream>
#include <cstdio>
using namespace std;
typedef long long LL;
const int N = 200010;
int n, a[N], cnt;
LL T, s = 2, ans = 0;
int main(){
cin >> n >> T;
for(int i = 1; i <= n; i++) scanf("%d", a + i);
while(s){
s = cnt = 0;
for(int i = 1; i <= n; i++)
if(s + a[i] <= T) s += a[i], cnt++;
ans += (T / s) * cnt;
T %= s;
}
return 0;
}

Codeforces Edu Round 53 A-D的更多相关文章

  1. Educational Codeforces Round 53 E. Segment Sum(数位DP)

    Educational Codeforces Round 53 E. Segment Sum 题意: 问[L,R]区间内有多少个数满足:其由不超过k种数字构成. 思路: 数位DP裸题,也比较好想.由于 ...

  2. Educational Codeforces Round 53 (Rated for Div. 2) (前五题题解)

    这场比赛没有打,后来补了一下,第五题数位dp好不容易才搞出来(我太菜啊). 比赛传送门:http://codeforces.com/contest/1073 A. Diverse Substring ...

  3. Codeforces Beta Round #49 (Div. 2)

    Codeforces Beta Round #49 (Div. 2) http://codeforces.com/contest/53 A #include<bits/stdc++.h> ...

  4. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  5. Codeforces Beta Round #62 题解【ABCD】

    Codeforces Beta Round #62 A Irrational problem 题意 f(x) = x mod p1 mod p2 mod p3 mod p4 问你[a,b]中有多少个数 ...

  6. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

  7. Codeforces Beta Round #13 C. Sequence (DP)

    题目大意 给一个数列,长度不超过 5000,每次可以将其中的一个数加 1 或者减 1,问,最少需要多少次操作,才能使得这个数列单调不降 数列中每个数为 -109-109 中的一个数 做法分析 先这样考 ...

  8. CodeForces Global Round 1

    CodeForces Global Round 1 CF新的比赛呢(虽然没啥区别)!这种报名的人多的比赛涨分是真的快.... 所以就写下题解吧. A. Parity 太简单了,随便模拟一下就完了. B ...

  9. Codeforces Global Round 1 - D. Jongmah(动态规划)

    Problem   Codeforces Global Round 1 - D. Jongmah Time Limit: 3000 mSec Problem Description Input Out ...

随机推荐

  1. CSP-S 2020 Travels

    CSP-S 2020 Travels DAY 0 I hit the board in the morning before departure The rest of the time is dec ...

  2. ceph unfound objects 处理

    ceph Vol 45 Issue 1 1.unfound objects blocking cluster, need help! Hi, I have a production cluster o ...

  3. 单独编译一个ext4内核模块

    当我们需要使用一个内核模块的时候,在当前使用版本内核编译的时候又没有加进去,在不改变内核版本的时候,再编译整个内核,可能会覆盖原来的内核,导致系统无法启动 现在我们能够单独选择需要的模块,然后加载进内 ...

  4. @Autowired自动装配原理

    在类中为类名添加 @Auwowired注解,为该类在spring中注册成组件 1,先按照类型在容器中找对应的组件:找到一个, 直接赋值,一个都没找到, 抛异常 2,找到了多个:按变量名作为ID继续匹配 ...

  5. MYSQL学习(三) --索引详解

    创建高性能索引 (一)索引简介 索引的定义 索引,在数据结构的查找那部分知识中有专门的定义.就是把关键字和它对应的记录关联起来的过程.索引由若干个索引项组成.每个索引项至少包含两部分内容.关键字和关键 ...

  6. 面试大厂,90%会被问到的Java面试题(附答案)

    面向对象的三个特征 封装,继承,多态 多态的好处,代码中如何实现多态,虚拟机中如何实现多态 允许不同类对象对同一消息作出相应,好处如下: 可替换性:多态对已存在的代码具有可替换性 可扩充性:增加新的子 ...

  7. netsniff使用

    1 netsniff安装与使用 首先直接下载源码包进行部署 安装一些前置包(安装完成的自动忽略) sudo apt install pkg-config sudo apt install libcli ...

  8. idea中安装阿里巴巴的代码规范插件

    1.打开iead软件,从左上角点击File  ->  Settings  ->  Plugins 2.安装完成后,重启idea软件,即可正常使用了.

  9. 15.java设计模式之访问者模式

    基本需求: 电脑需要键盘鼠标等固定的组件组成 现在分为个人,组织等去买电脑,而同一种组件对不同的人(访问者)做出不同的折扣,从而电脑的价格也不一样 传统的解决方法:在组件内部进行判断访问人的类型,从而 ...

  10. java实验作业1

    1 //1已知圆的半径为10,求其周长及面积 2 package calsswork3; 3 4 public class test3_1 { 5 //求周长 6 public static doub ...