A. Codeforces Checking

题意

每个案例给一个字符,如果在 ”codeforces“ 中出现过,输出 YES,否则输出 NO

code

/**
* @author :Changersh
* @date : 2023/2/3 22:37
*/ import java.io.*;
import java.util.*;
import java.lang.*; public class Main {
private static boolean[] a = new boolean[26];
public static void main(String[] args) {
String s = "codeforces";
for (int i = 0; i < s.length(); i++)
a[s.charAt(i) - 'a'] = true; int n = sc.nextInt();
for (int i = 0; i < n; i++) {
char t = sc.next().charAt(0);
if (a[t - 'a']) out.println("YES");
else out.println("NO");
} out.close();
}
static class FastScanner{
// 看看有没有溢出,是否要用 long
// sc.xxx;
// out.print();
// out.flush();
// out.close();
BufferedReader br;
StringTokenizer st;
public FastScanner(InputStream in) {
br=new BufferedReader( new InputStreamReader(System.in));
eat("");
}
public void eat(String s) {
st=new StringTokenizer(s);
} public String nextLine() {
try {
return br.readLine();
}catch(IOException e) {
return null;
}
} public boolean hasNext() {
while(!st.hasMoreTokens()) {
String s=nextLine();
if(s==null)return false;
eat(s);
} return true;
} public String next() {
hasNext();
return st.nextToken();
} public int nextInt() {
return Integer.parseInt(next());
} public long nextLong() {
return Long.parseLong(next());
} public double nextDouble() {
return Double.parseDouble(next());
}
} static FastScanner sc=new FastScanner(System.in);
static PrintWriter out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
}

B. Following Directions

题意

每个案例给一串字符串,包含 U、D、L、R,是上下左右四个方向,从 (0, 0) 开始,问是否经过 (1, 1)

code

直接模拟即可

/**
* @author :Changersh
* @date : 2023/2/3 22:43
*/ import java.io.*;
import java.util.*;
import java.lang.*; public class Main {
private static int N = 55, n, T;
public static void main(String[] args) {
T = sc.nextInt();
while (T-- > 0) {
out.println(solve() ? "YES" : "NO");
} out.close();
} private static boolean solve() {
n = sc.nextInt();
char[] c = sc.next().toCharArray();
int x = 0, y = 0;
for (int i = 0; i < n; i++) {
if (c[i] == 'U') x++;
else if (c[i] == 'D') x--;
else if (c[i] == 'L') y--;
else y++;
if (x == 1 && y == 1) return true;
} return false;
} static class FastScanner {
// 看看有没有溢出,是否要用 long
// sc.xxx;
// out.print();
// out.flush();
// out.close();
BufferedReader br;
StringTokenizer st; public FastScanner(InputStream in) {
br = new BufferedReader(new InputStreamReader(System.in));
eat("");
} public void eat(String s) {
st = new StringTokenizer(s);
} public String nextLine() {
try {
return br.readLine();
} catch (IOException e) {
return null;
}
} public boolean hasNext() {
while (!st.hasMoreTokens()) {
String s = nextLine();
if (s == null) return false;
eat(s);
} return true;
} public String next() {
hasNext();
return st.nextToken();
} public int nextInt() {
return Integer.parseInt(next());
} public long nextLong() {
return Long.parseLong(next());
} public double nextDouble() {
return Double.parseDouble(next());
}
} static FastScanner sc = new FastScanner(System.in);
static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
}

C. Prepend and Append

题意

给你一串由 0 1 组成的字符串,如果第一个和最后一个是 0 1或者 1 0 ,可以消掉,这种操作可以进行任意次,问,任意次操作后,字符串剩下的最短长度是多少?

code

双指针判断第一个和最后一个字符,模拟即可

/**
* @author :Changersh
* @date : 2023/2/3 22:51
*/ import java.io.*;
import java.util.*;
import java.lang.*; public class Main {
private static int T;
public static void main(String[] args) {
T = sc.nextInt();
while (T-- > 0)
solve(); out.close();
}
private static void solve() {
int n = sc.nextInt();
char[] c = sc.next().toCharArray(); int l = 0, r = n - 1;
while (l < r) {
if ((c[l] == '0' && c[r] == '1') || (c[l] == '1' && c[r] == '0')) {
l++;
r--;
}
else break;
} out.println(r - l + 1);
}
static class FastScanner{
// 看看有没有溢出,是否要用 long
// sc.xxx;
// out.print();
// out.flush();
// out.close();
BufferedReader br;
StringTokenizer st;
public FastScanner(InputStream in) {
br=new BufferedReader( new InputStreamReader(System.in));
eat("");
}
public void eat(String s) {
st=new StringTokenizer(s);
} public String nextLine() {
try {
return br.readLine();
}catch(IOException e) {
return null;
}
} public boolean hasNext() {
while(!st.hasMoreTokens()) {
String s=nextLine();
if(s==null)return false;
eat(s);
} return true;
} public String next() {
hasNext();
return st.nextToken();
} public int nextInt() {
return Integer.parseInt(next());
} public long nextLong() {
return Long.parseLong(next());
} public double nextDouble() {
return Double.parseDouble(next());
}
} static FastScanner sc=new FastScanner(System.in);
static PrintWriter out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
}

D. Distinct Split

题意

每个案例给定一个由小写字母组成的字符串,求将字符串从中间劈开,分成两个字串中,出现的不同的字符数的和的最大值?

code

暴力写会tle,所以先预处理一下前缀和后缀,前缀是到 第 i 个字符截止,前面 i 个字符共出现多少个不同的字符

后缀:从

/**
* @author :Changersh
* @date : 2023/2/3 23:04
*/ import java.io.*;
import java.util.*;
import java.lang.*; public class Main {
private static int T, n;
private static char[] c; public static void main(String[] args) {
T = sc.nextInt();
while (T-- > 0)
solve(); out.close();
} private static void solve() {
n = sc.nextInt();
c = sc.next().toCharArray();
int ans = 0;
int[] l = new int[n + 2];
int[] r = new int[n + 2];
get(l, r); for (int i = 0; i < n; i++) {
ans = Math.max(ans, l[i + 1] + r[i + 2]);
} out.println(ans);
} private static void get(int[] l, int[] r) {
int ans = 0;
HashSet<Character> vis = new HashSet<>();
for (int i = 0; i < n; i++) {
if (!vis.contains(c[i])) {
vis.add(c[i]);
ans++;
}
l[i + 1] = ans;
}
vis.clear();
ans = 0;
for (int i = n - 1; i >= 0; i--) {
if (!vis.contains(c[i])) {
vis.add(c[i]);
ans++;
}
r[i + 1] = ans;
}
} static class FastScanner {
// 看看有没有溢出,是否要用 long
// sc.xxx;
// out.print();
// out.flush();
// out.close();
BufferedReader br;
StringTokenizer st; public FastScanner(InputStream in) {
br = new BufferedReader(new InputStreamReader(System.in));
eat("");
} public void eat(String s) {
st = new StringTokenizer(s);
} public String nextLine() {
try {
return br.readLine();
} catch (IOException e) {
return null;
}
} public boolean hasNext() {
while (!st.hasMoreTokens()) {
String s = nextLine();
if (s == null) return false;
eat(s);
} return true;
} public String next() {
hasNext();
return st.nextToken();
} public int nextInt() {
return Integer.parseInt(next());
} public long nextLong() {
return Long.parseLong(next());
} public double nextDouble() {
return Double.parseDouble(next());
}
} static FastScanner sc = new FastScanner(System.in);
static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
}

E. Negatives and Positives

题意

给定一串数字,你可以进行任意次以下的操作:

选择两个不同的数字,变成相反数

求,进行任意次之后,数组数字和的最大值是多少?

code

数字有正数、负数、0

翻转的时候,最佳的方法是把所有的负数都变成正数,是最佳情况

  1. 负数个数是偶数,完美,全部都可以翻转成正数
  2. 负数个数是奇数:

    1. 有 0,依然完美

    2. 找绝对值最小的,取负即可

    将第二种情况的两种小情况和一

    遍历数组的时候,统计负数个数,并且把负数都翻转,求和

    如果是偶数,返回答案

    如果是奇数,说明不能完美翻转,数组排序,得到最小的数字,无论是正数还是负数。抑或是 0,减两次即可。

因为最小的如果是 负数翻转的,减两次相当于没有翻转

如果是正数,相当于把 落单的负数和绝对值小于它的正数翻转,和变大

如果是 0,也是完美的情况

/**
* @author :Changersh
* @date : 2023/2/4 9:20
*/ import java.io.*;
import java.util.*;
import java.lang.*; public class Main {
private static int T, n, N = 200010;
private static int[] a;
public static void main(String[] args) {
T = sc.nextInt();
while (T-- > 0)
solve(); out.close();
}
private static void solve() {
long sum = 0;
int cnt = 0;
n = sc.nextInt();
a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = sc.nextInt();
if (a[i] < 0) {
cnt++;
a[i] = -a[i];
}
sum += a[i];
} if ((cnt & 1) == 1) {
Arrays.sort(a);
sum -= 2 * a[0];
}
out.println(sum);
}
static class FastScanner{
// 看看有没有溢出,是否要用 long
// sc.xxx;
// out.print();
// out.flush();
// out.close();
BufferedReader br;
StringTokenizer st;
public FastScanner(InputStream in) {
br=new BufferedReader( new InputStreamReader(System.in));
eat("");
}
public void eat(String s) {
st=new StringTokenizer(s);
} public String nextLine() {
try {
return br.readLine();
}catch(IOException e) {
return null;
}
} public boolean hasNext() {
while(!st.hasMoreTokens()) {
String s=nextLine();
if(s==null)return false;
eat(s);
} return true;
} public String next() {
hasNext();
return st.nextToken();
} public int nextInt() {
return Integer.parseInt(next());
} public long nextLong() {
return Long.parseLong(next());
} public double nextDouble() {
return Double.parseDouble(next());
}
} static FastScanner sc=new FastScanner(System.in);
static PrintWriter out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
}

G1. Teleporters (Easy Version)

题意

有 0~n,n + 1个点,我们可以从 1 ~ n 号点用 传送器瞬间移动到 0号点,花费 a[i] 块钱

从一个点移动到隔壁,花费 1 块钱

给你一串 传送的花费 和现在总共有的钱 ,问从 0 出发最多能用几次传送

由题意得,传送的使用条件是:

  1. 先花费 i 块钱,从 0 走到 i
  2. 花费 a[i] 传送

code


Codeforces Round #849 (Div. 4)的更多相关文章

  1. 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 ...

  2. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  3. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  4. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  5. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  6. 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 ...

  7. 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 ...

  8. Codeforces Round #371 (Div. 1)

    A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...

  9. Codeforces Round #268 (Div. 2) ABCD

    CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...

  10. 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts

    题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...

随机推荐

  1. netty系列之:在netty中使用proxy protocol

    目录 简介 netty对proxy protocol协议的支持 HAProxyMessage的编码解码器 netty中proxy protocol的代码示例 总结 简介 我们知道proxy proto ...

  2. 【离线数仓】Day04-即席查询(Ad Hoc):Presto链接不同数据源查询、Druid建多维表、Kylin使用cube快速查询

    一.Presto 1.简介 概念:大数据量.秒级.分布式SQL查询engine[解析SQL但不是数据库] 架构 不同worker对应不同的数据源(各数据源有对应的connector连接适配器) 优缺点 ...

  3. 项目完成小结 - Django-React-Docker-Swag部署配置

    前言 最近有个项目到一段落,做个小结记录. 内容可能会多次补充,在博客上实时更新哈~ 如果是在公众号阅读这篇文章,可以点击「查看原文」访问最新版本~ 这个项目是前后端分离,后端为了快,依然用我的Dja ...

  4. Github Actions 学习笔记

    Github Actions是什么? Github Actions 官方介绍:GitHub Actions是一个持续集成和持续交付(CI/CD)平台,允许您自动化构建.测试和部署管道.您可以创建构建和 ...

  5. MassTransit 知多少 | 基于MassTransit Courier实现Saga 编排式分布式事务

    Saga 模式 Saga 最初出现在1987年Hector Garcaa-Molrna & Kenneth Salem发表的一篇名为<Sagas>的论文里.其核心思想是将长事务拆分 ...

  6. 视图 触发器 事务 MVCC 存储过程 MySQL函数 MySQL流程控制 索引的数据结构 索引失效 慢查询优化explain 数据库设计三范式

    目录 视图 create view ... as 触发器 简介 创建触发器的语法 create trigger 触发器命名有一定的规律 临时修改SQL语句的结束符 delimiter 触发器的实际运用 ...

  7. 【机器学习】李宏毅——Unsupervised Learning

    读这篇文章之间欢迎各位先阅读我之前写过的线性降维的文章.这篇文章应该也是属于Unsupervised Learning的内容的. Neighbor Embedding Manifold Learnin ...

  8. [python] 基于paramiko库操作远程服务器

    SSH(Secure Shell)是一种网络安全协议,能够使两台计算机安全地通信和共享数据.目前,SSH协议已在世界各地广泛使用,大多数设备都支持SSH功能.SSH的进一步说明见:深入了解SSH.SS ...

  9. 为什么 java 容器推荐使用 ExitOnOutOfMemoryError 而非 HeapDumpOnOutOfMemoryError ?

    前言 好久没写文章了, 今天之所以突然心血来潮, 是因为昨天出现了这样一个情况: 我们公司的某个手机APP后端的用户(customer)微服务出现内存泄露, 导致OutOfMemoryError, 但 ...

  10. js鼠标轨迹特效

    今天无意中访问到了开源社区 (apiopen.top)的主界面,发现鼠标跟随的特效不错(残留轨迹),弄下来玩玩 上代码 整合后只需要两部分,导入JS依赖后,在html 添加 id 为 mouseCan ...