当前位置:网站首页>Codeforces Round #806 (Div. 4)
Codeforces Round #806 (Div. 4)
2022-07-16 06:50:00 【Changersh】
A. YES or YES?
There is a string of length , consisting of uppercase and lowercase English letters. Check if it is equal to “YES” (without quotes), where each letter can be in any case. For example, “yES”, “Yes”, “yes” are all allowable.
Input
The first line of the input contains an integer () — the number of testcases.
The description of each test consists of one line containing one string consisting of three characters. Each character of is either an uppercase or lowercase English letter.
Output
For each test case, output “YES” (without quotes) if satisfies the condition, and “NO” (without quotes) otherwise.
You can output “YES” and “NO” in any case (for example, strings “yES”, “yes” and “Yes” will be recognized as a positive response).
Example
inputCopy
10
YES
yES
yes
Yes
YeS
Noo
orZ
yEz
Yas
XES
outputCopy
YES
YES
YES
YES
YES
NO
NO
NO
NO
NO
Note
The first five test cases contain the strings “YES”, “yES”, “yes”, “Yes”, “YeS”. All of these are equal to “YES”, where each character is either uppercase or lowercase.
思路
判断是否是yes,不分大小写,直接判断即可
签到
/** * @author Changersh * @date 2022/7/12 22:36 */
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int T = scanner.nextInt();
while (T-- > 0) {
char s[] = scanner.next().toCharArray();
if ((s[0] == 'y' || s[0] == 'Y') && (s[1] == 'e' || s[1] == 'E') && (s[2] == 's' || s[2] == 'S'))
System.out.println("YES");
else
System.out.println("NO");
}
}
}
B. ICPC Balloons
In an ICPC contest, balloons are distributed as follows:
Whenever a team solves a problem, that team gets a balloon.
The first team to solve a problem gets an additional balloon.
A contest has 26 problems, labelled A, B, C, …, Z. You are given the order of solved problems in the contest, denoted as a string , where the -th character indicates that the problem has been solved by some team. No team will solve the same problem twice.
Determine the total number of balloons that the teams recieved. Note that some problems may be solved by none of the teams.
Input
The first line of the input contains an integer () — the number of testcases.
The first line of each test case contains an integer () — the length of the string.
The second line of each test case contains a string of length consisting of uppercase English letters, denoting the order of solved problems.
Output
For each test case, output a single integer — the total number of balloons that the teams received.
Example
inputCopy
6
3
ABA
1
A
3
ORZ
5
BAAAA
4
BKPT
10
CODEFORCES
outputCopy
5
2
6
7
8
17
Note
In the first test case, balloons are given out:
Problem A is solved. That team receives balloons: one because they solved the problem, an an additional one because they are the first team to solve problem A.
Problem B is solved. That team receives balloons: one because they solved the problem, an an additional one because they are the first team to solve problem B.
Problem A is solved. That team receives only balloon, because they solved the problem. Note that they don’t get an additional balloon because they are not the first team to solve problem A.
The total number of balloons given out is .
In the second test case, there is only one problem solved. The team who solved it receives balloons: one because they solved the problem, an an additional one because they are the first team to solve problem A.
思路
题目大意就是若干题目 A-Z,做出来一道给一个气球,第一个做出来某道题的 额外奖励一个,给你一个字符串,是多个队伍获得做题的顺序,统计总共的气球
遍历一遍,第一次出现之后标记一下就好
桶标记?
/** * @author Changersh * @date 2022/7/12 22:43 */
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int T = scanner.nextInt();
while (T-- > 0) {
int n = scanner.nextInt();
int[] vis = new int[26];
Arrays.fill(vis, 0);
int ans = 0;
char[] ch = scanner.next().toCharArray();
for (int i = 0; i < n; i++) {
if (vis[ch[i] - 'A'] == 0) {
ans += 2;
vis[ch[i] - 'A'] = 1;
}
else ans += 1;
}
System.out.println(ans);
}
}
}
C. Cypher
Luca has a cypher made up of a sequence of wheels, each with a digit written on it. On the -th wheel, he made moves. Each move is one of two types:
up move (denoted by ): it increases the -th digit by . After applying the up move on , it becomes .
down move (denoted by ): it decreases the -th digit by . After applying the down move on , it becomes .
Example for . The current sequence is 0 0 0 0.
Luca knows the final sequence of wheels and the moves for each wheel. Help him find the original sequence and crack the cypher.
Input
The first line contains a single integer () — the number of test cases.
The first line of each test case contains a single integer () — the number of wheels.
The second line contains integers () — the digit shown on the -th wheel after all moves have been performed.
Then lines follow, the -th of which contains the integer () and characters that are either or — the number of moves performed on the -th wheel, and the moves performed. and represent an up move and a down move respectively.
Output
For each test case, output space-separated digits — the initial sequence of the cypher.
Example
inputCopy
3
3
9 3 1
3 DDD
4 UDUU
2 DU
2
0 9
9 DDDDDDDDD
9 UUUUUUUUU
5
0 5 9 8 3
10 UUUUUUUUUU
3 UUD
8 UUDUUDDD
10 UUDUUDUDDU
4 UUUU
outputCopy
2 1 1
9 0
0 4 9 6 9
Note
In the first test case, we can prove that initial sequence was . In that case, the following moves were performed:
On the first wheel: .
On the second wheel: .
On the third wheel: .
The final sequence was , which matches the input.
思路
有一个密码锁,上面是n位的密码,每一位都是 0 - 9,你可以进行两个操作
1.D :当前的这一位密码 + 1
2.U:当前位数字 -1,如果是0 - 1 --> 9
现在给你m次操作之后的密码,和m次操作,让你来给出操作之前的密码
直接逆向模拟就好了,原来的 D 是+1,逆过来就是 -1 规则也是 0-1 = 9
U原来是-1,这里变成 +1,每次直接对 10取模即可
模拟
/** * @author Changersh * @date 2022/7/12 22:51 */
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int T = scanner.nextInt();
while (T-- > 0) {
int n = scanner.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = scanner.nextInt();
for (int i = 0; i < n; i++) {
int t = scanner.nextInt();
char[] s = scanner.next().toCharArray();
for (int j = 0; j < s.length; j++) {
if (s[j] == 'D') {
a[i] = (a[i] + 1) % 10;
} else if (s[j] == 'U') {
a[i]--;
if (a[i] == -1) a[i] = 9;
}
}
}
for (int i = 0; i < n; i++)
System.out.print(a[i] + " ");
System.out.println();
}
}
}
D. Double Strings
You are given strings of length at most .
For each string , determine if there exist two strings and such that . That is, is the concatenation of and . Note that can be equal to .
Recall that the concatenation of strings and is , where and are the lengths of strings and respectively. For example, concatenation of “code” and “forces” is “codeforces”.
Input
The first line contains a single integer () — the number of test cases.
The first line of each test case contains a single integer () — the number of strings.
Then lines follow, the -th of which contains non-empty string of length at most , consisting of lowercase English letters. Among the given strings, there may be equal (duplicates).
The sum of over all test cases doesn’t exceed .
Output
For each test case, output a binary string of length . The -th bit should be if there exist two strings and where , and otherwise. Note that can be equal to .
Example
inputCopy
3
5
abab
ab
abc
abacb
c
3
x
xx
xxx
8
codeforc
es
codes
cod
forc
forces
e
code
outputCopy
10100
011
10100101
Note
In the first test case, we have the following:
, since . Remember that can be equal to .
is not the concatenation of any two strings in the list.
, since .
is not the concatenation of any two strings in the list.
is not the concatenation of any two strings in the list.
Since only and satisfy the conditions, only the first and third bits in the answer should be , so the answer is .
思路
题意是给你一组字符串,让你判断每个字符串能不能由这一组中的其他的两个字符串拼接而成(这两个可以是同一个复制一次那种)
如果可以返回1,不可以返回0
这里数据量较少,所以尝试直接暴力遍历匹配
先将一组的字符串都加入HashSet,同时也加入String的数组(或者是用char数组,但是好像太麻烦了,我写的就很麻烦)
遍历一组的每一个字符串,然后从第一个位置开始,切割成两个子串,判断是否存在即可
HashSet + subString 暴力
enmm,这里不应该用char的,发现并没有对String进行修改,所以还是用String数组更方便一些
顺便说,装箱成String,1. new String(…),2. = String.valueOf()
package D;
/** * @author Changersh * @date 2022/7/12 23:00 */
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int T = scanner.nextInt();
while (T-- > 0) {
int n = scanner.nextInt();
HashSet<String> st = new HashSet<>();
char[][] s = new char[n + 1][10];
for (int i = 0; i < n; i++) {
String str = scanner.next();
s[i] = str.toCharArray();
st.add(str);
}
for (int i = 0; i < n; i++) {
boolean flag = true;
for (int j = 1; j < s[i].length; j++) {
String str = String.valueOf(s[i]);
String s1 = str.substring(0, j);
String s2 = str.substring(j);
if (st.contains(s1) && st.contains(s2)) {
System.out.print("1");
flag = false;
break;
}
}
if (flag)
System.out.print("0");
}
System.out.println();
}
}
}
边栏推荐
- Pyramid thinking learning
- Vulnhub-dc8 learning notes
- Operation of simulated examination platform for 2022 G2 boiler stoker examination
- 书写更自然,媲美原厂体验,南卡Pencil电容笔上手
- 05 gulimall VirtualBox set fixed IP for virtual machine
- Address problem when Xilinx FPGA starts configuration data from SPI flash
- Boyun was selected as the representative manufacturer of Gartner China cloud management tool market guide
- Failure of CUDA installation nsight visual studio edition failed
- ZYNQ PL中断脉冲多久可以被CPU捕获到
- 亚马逊卖家该如何做好防关联?不砍单!(测评自养号详解)
猜你喜欢
![[server data recovery] a case of RAID5 data recovery of an IBM model storage](/img/7b/5c8b36ea91f0cef878a01b3c00f16f.jpg)
[server data recovery] a case of RAID5 data recovery of an IBM model storage

Failure of CUDA installation nsight visual studio edition failed

架构基础篇

书写更自然,媲美原厂体验,南卡Pencil电容笔上手

Address problem when Xilinx FPGA starts configuration data from SPI flash

Distributed notes (01) - theory and principle of distributed cap

Onnx model tensor shapes information and flops statistical tools

景联文科技数据采集公司:严格把控工期,为AI企业输送高质量数据
![[dynamic memory allocation]](/img/29/ef88425f0f1b6e775793b6e51c2170.png)
[dynamic memory allocation]

Small target detection 2_ OHEM
随机推荐
指针进阶(五)——回调函数
Func () {} () is a strange way of writing. I don't know what category it belongs to
Exception: Unexpected end of ZLIB input stream
SLAM_ Rotational kinematics_ Relationship between velocity V and acceleration a in two coordinate systems
AcWing 3619. Date date processing
【成像】【8】太赫兹光学——波束耦合,高阶高斯波束模型
「TakinTalks」_ 故障频繁发生,如何做好系统稳定性?
Splash integrates with Acronis to provide scalable remote support
Learning experience sharing 6: experience sharing of Dr. dry goods
博云入选 Gartner 中国云管理工具市场指南代表厂商
GooglePhoto设置壁纸----壁纸裁剪界面配置
Googlephoto setting Wallpaper - wallpaper clipping interface configuration
Preparation for the computer test of Baosteel 15: a master of string processing
Comprehensive evaluation method
MIPI C-PHY科普
[daily training] 558 Intersection of quadtree
HTAP (hybrid transaction and) of polardb for PostgreSQL
Operation of simulated examination platform for 2022 G2 boiler stoker examination
The difference between arrayslist and LinkedList
【通信】【1】幅度调制,频率调制,双边带与单边带,IQ与PSK与QAM——采样一定要满足奈奎斯特定理吗