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. combotree 的简单使用

    一.前端 combotree HTML: <input id="201711281652407353448711985811" class="easyUI-comb ...

  2. DHorse的链路追踪

    目前,DHorse的链路追踪功能是通过SkyWalking来实现.实现原理是DHorse在部署应用时,通过指定SkyWalking的Agent来收集服务的调用链路信息.下面就来具体看一下DHorse如 ...

  3. Nginx 安装篇-yum安装

    yum安装教程引用: https://www.cnblogs.com/AprilBlank/p/11388990.html#1-yum安装推荐 避坑事项: 暂无

  4. 【Java EE】Day09 JavaScript基础、ECMAScript语法、Java对象

    一.简介 1.概念 客户端脚本语言 脚本语言:无需编译,直接被解析执行 运行在:客户端浏览器,每个浏览器都有解析引擎 功能: 用户与页面交互 控制html元素 使页面产生动态效果 2.发展史 1992 ...

  5. 【Scala】思维导图

    思维导图:http://naotu.baidu.com/file/8ac705df572cd2f131aff5f0ed9c4c88?token=871f7d35671c6287 Scala 算术运算 ...

  6. Karmada多云多集群生产实践专场圆满落幕

    摘要:CNCF Karmada社区Cloud Native Days China 2022南京站成功举办. 本文分享自华为云社区<Karmada多云多集群生产实践专场圆满落幕|Cloud Nat ...

  7. C++进阶(map+set容器模拟实现)

    关联式容器 关联式容器也是用来存储数据的,与序列式容器(如vector.list等)不同的是,其里面存储的是<key,value>结构的键值对,在数据检索时比序列式容器效率更高.今天要介绍 ...

  8. vue移动端封装底部导航

    <template> <div class="myfooter flex-betweenCenter"> <router-link tag=" ...

  9. 2、postman调试

    Postman接口调试: postman博客参考 Postman是一个API(接口)开发协作平台,其提供了发送请求.检查响应.自动化测试.数据模拟.服务监控.文档分享等一系列与API(接口)开发有关的 ...

  10. CH32V307 内部10M网络工程创建流程

    说明: 本次操作是基于目前MRSV1.8.0版本,以及WCH官网CH32V307-V1.8版本的例程操作. MRS链接:http://www.mounriver.com/download CH32V3 ...