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. 嵌入式-c语言基础:冒泡排序实现从大到小排列

    #include<stdio.h> int main() { /*冒泡排序:从大到小*/ /*i=0 第1轮(i+1):需要比较9次(sizeArr-i-1)*/ /*i=1 第2轮(i+ ...

  2. c++题目:数迷

    c++题目:数迷 题目 [题目描述] 给出含有N×N个格子的正方形表格,要求每个格子都填上一个个位数(范围1-N),使得每行.每列以及同一斜线上的数字都不同.部分格子已经填好数字.求满足题意的方案数. ...

  3. devexpress中dockManager保存布局后恢复不正常

    在使用dockManager保存布局后进行恢复发现不正常,与中间的gridcontorl接触的都不行.gridcontorl设置的填充是fill 所以在在界面上再添加一个PanelControl控件并 ...

  4. Base64 学习

    base64是什么 Base64,就是包括小写字母a-z,大写字母A-Z,数字0-9,符号"+" "/ "一共64个字符的字符集,(另加一个"=&qu ...

  5. 关于解决windows安装gcc g++环境 mingw失败

    前言 这几天学习c++,为了详细了解编译过程我没有安装vs全家桶,当然使用命令行是最好的方法. 但是为了解决这个网络问题折腾了我很久,经过我研究发现,其实就是到固定网站下载几个压缩格式的文件,然后解压 ...

  6. linux 挂载 vdi 文件(virtual box虚拟机镜像文件)

    1. 下载 vdfuse 下载地址 2.解压deb文件 解压deb安装包文件,这里不使用安装命令是因为你的virtualbox 可能和vdfuse的版本不一致,导致安装失败,而我们只需要用到 vdfu ...

  7. 规则引擎Drools在贷后催收业务中的应用

    作者:vivo 互联网服务器团队- Feng Xiang 在日常业务开发工作中我们经常会遇到一些根据业务规则做决策的场景.为了让开发人员从大量的规则代码的开发维护中释放出来,把规则的维护和生成交由业务 ...

  8. vue3响应式原理以及ref和reactive区别还有vue2/3生命周期的对比,第二天

    前言: 前天我们学了 ref 和 reactive ,提到了响应式数据和 Proxy ,那我们今天就来了解一下,vue3 的响应式 在了解之前,先复习一下之前 vue2 的响应式原理 vue2 的响应 ...

  9. 【每日一题】【初始节点初始化,前一个为空】2022年1月7日-NC78 反转链表

    描述给定一个单链表的头结点pHead,长度为n,反转该链表后,返回新链表的表头. 数据范围: n\leq1000n≤1000要求:空间复杂度 O(1)O(1) ,时间复杂度 O(n)O(n) . 如当 ...

  10. gulp4.0构建任务

    执行default任务时,依次执行以下任务 gulp.task('default', ['htmlmin', 'cssmin', 'jsmin', 'copy']); 报错:Task function ...