当前位置:网站首页>Codeforces Round #784 (Div. 4)
Codeforces Round #784 (Div. 4)
2022-04-23 06:35:00 【Changersh】
A. Division?
Codeforces separates its users into 4 divisions by their rating:
For Division 1: 1900≤rating
For Division 2: 1600≤rating≤1899
For Division 3: 1400≤rating≤1599
For Division 4: rating≤1399
Given a rating, print in which division the rating belongs.
Input
The first line of the input contains an integer t (1≤t≤104) — the number of testcases.
The description of each test consists of one line containing one integer rating (−5000≤rating≤5000).
Output
For each test case, output a single line containing the correct division in the format “Division X”, where X is an integer between 1 and 4 representing the division for the corresponding rating.
Example
inputCopy
7
-789
1299
1300
1399
1400
1679
2300
outputCopy
Division 4
Division 4
Division 4
Division 4
Division 3
Division 2
Division 1
Note
For test cases 1−4, the corresponding ratings are −789, 1299, 1300, 1399, so all of them are in division 4.
For the fifth test case, the corresponding rating is 1400, so it is in division 3.
For the sixth test case, the corresponding rating is 1679, so it is in division 2.
For the seventh test case, the corresponding rating is 2300, so it is in division 1.
代码
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int T, a;
scanf("%d", &T);
while (T--) {
scanf("%d", &a);
if (a >= 1900)
printf("Division 1\n");
else if (a >= 1600 && a <= 1899)
printf("Division 2\n");
else if (a >= 1400 && a <= 1599)
printf("Division 3\n");
else if (a <= 1399)
printf("Division 4\n");
}
return 0;
}
B. Triple
Given an array a of n elements, print any value that appears at least three times or print -1 if there is no such value.
Input
The first line contains an integer t (1≤t≤104) — the number of test cases.
The first line of each test case contains an integer n (1≤n≤2⋅105) — the length of the array.
The second line of each test case contains n integers a1,a2,…,an (1≤ai≤n) — the elements of the array.
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.
Output
For each test case, print any value that appears at least three times or print -1 if there is no such value.
Example
inputCopy
7
1
1
3
2 2 2
7
2 2 3 3 4 2 2
8
1 4 3 4 3 2 4 1
9
1 1 1 2 2 2 3 3 3
5
1 5 2 4 3
4
4 4 4 4
outputCopy
-1
2
2
4
3
-1
4
Note
In the first test case there is just a single element, so it can’t occur at least three times and the answer is -1.
In the second test case, all three elements of the array are equal to 2, so 2 occurs three times, and so the answer is 2.
For the third test case, 2 occurs four times, so the answer is 2.
For the fourth test case, 4 occurs three times, so the answer is 4.
For the fifth test case, 1, 2 and 3 all occur at least three times, so they are all valid outputs.
For the sixth test case, all elements are distinct, so none of them occurs at least three times and the answer is -1.
题目大意:
输入一堆数字,如果有一个数字出现了三次及以上,就输出这个数字,如果有多个数字,任意输出一个即可,如果没有就输出-1;
代码
输入的时候直接用map接着,然后判断大于等于3的记录一下,最后的时候输出就好了;
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
int T, n;
int main() {
scanf("%d", &T);
while (T--) {
bool flag = false;
map<int, int> mp;
scanf("%d", &n);
while (n--) {
int a;
scanf("%d", &a);
mp[a]++;
if (mp[a] >= 3 && flag == false) {
printf("%d\n", a);
flag = true;
}
}
if (flag == false) printf("-1\n");
}
return 0;
}
C. Odd/Even Increments
Given an array a=[a1,a2,…,an] of n positive integers, you can do operations of two types on it:
Add 1 to every element with an odd index. In other words change the array as follows: a1:=a1+1,a3:=a3+1,a5:=a5+1,….
Add 1 to every element with an even index. In other words change the array as follows: a2:=a2+1,a4:=a4+1,a6:=a6+1,….
Determine if after any number of operations it is possible to make the final array contain only even numbers or only odd numbers. In other words, determine if you can make all elements of the array have the same parity after any number of operations.
Note that you can do operations of both types any number of times (even none). Operations of different types can be performed a different number of times.
Input
The first line contains an integer t (1≤t≤100) — the number of test cases.
The first line of each test case contains an integer n (2≤n≤50) — the length of the array.
The second line of each test case contains n integers a1,a2,…,an (1≤ai≤103) — the elements of the array.
Note that after the performed operations the elements in the array can become greater than 103.
Output
Output t lines, each of which contains the answer to the corresponding test case. As an answer, output “YES” if after any number of operations it is possible to make the final array contain only even numbers or only odd numbers, and “NO” otherwise.
You can output the answer in any case (for example, the strings “yEs”, “yes”, “Yes” and “YES” will be recognized as a positive answer).
Example
inputCopy
4
3
1 2 1
4
2 2 2 3
4
2 2 2 2
5
1000 1 1000 1 1000
outputCopy
YES
NO
YES
YES
Note
For the first test case, we can increment the elements with an even index, obtaining the array [1,3,1], which contains only odd numbers, so the answer is “YES”.
For the second test case, we can show that after performing any number of operations we won’t be able to make all elements have the same parity, so the answer is “NO”.
For the third test case, all elements already have the same parity so the answer is “YES”.
For the fourth test case, we can perform one operation and increase all elements at odd positions by 1, thus obtaining the array [1001,1,1001,1,1001], and all elements become odd so the answer is “YES”.
题目大意:
给定一个int数组,每次可以对所有奇数位置的数字都+1,或者偶数位置都+1,可以操作任意次数,也可以一次也不操作。判断最后是否能让所有的数字同时奇数或者偶数
代码
只需要判断同是偶数位置或者奇数位置上面有没有一个是奇数一个是偶数的,如果有就no
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int T, n;
int main() {
scanf("%d", &T);
while (T--) {
scanf("%d", &n);
int a, p = 0, q = 0, r = 0, s = 0;
for (int i = 1; i <= n; i++) {
scanf("%d", &a);
if (i % 2) {
if (a % 2) p = 1;
else q = 1;
}
else {
if (a % 2) r = 1;
else s = 1;
}
}
if ((p == 1 && q == 1) || (r == 1 && s == 1))
printf("NO\n");
else
printf("YES\n");
}
return 0;
}
E. 2-Letter Strings
Given n strings, each of length 2, consisting of lowercase Latin alphabet letters from ‘a’ to ‘k’, output the number of pairs of indices (i,j) such that i<j and the i-th string and the j-th string differ in exactly one position.
In other words, count the number of pairs (i,j) (i<j) such that the i-th string and the j-th string have exactly one position p (1≤p≤2) such that sip≠sjp.
The answer may not fit into 32-bit integer type, so you should use 64-bit integers like long long in C++ to avoid integer overflow.
Input
The first line of the input contains a single integer t (1≤t≤100) — the number of test cases. The description of test cases follows.
The first line of each test case contains a single integer n (1≤n≤105) — the number of strings.
Then follows n lines, the i-th of which containing a single string si of length 2, consisting of lowercase Latin letters from ‘a’ to ‘k’.
It is guaranteed that the sum of n over all test cases does not exceed 105.
Output
For each test case, print a single integer — the number of pairs (i,j) (i<j) such that the i-th string and the j-th string have exactly one position p (1≤p≤2) such that sip≠sjp.
Please note, that the answer for some test cases won’t fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++).
Example
inputCopy
4
6
ab
cb
db
aa
cc
ef
7
aa
bb
cc
ac
ca
bb
aa
4
kk
kk
ab
ab
5
jf
jf
jk
jk
jk
outputCopy
5
6
0
6
Note
For the first test case the pairs that differ in exactly one position are: (“ab”, “cb”), (“ab”, “db”), (“ab”, “aa”), (“cb”, “db”) and (“cb”, “cc”).
For the second test case the pairs that differ in exactly one position are: (“aa”, “ac”), (“aa”, “ca”), (“cc”, “ac”), (“cc”, “ca”), (“ac”, “aa”) and (“ca”, “aa”).
For the third test case, the are no pairs satisfying the conditions.
题目大意:
给n个字符串,每个字符串含2个字符,遍历,判断和该字符串只差一个字符不相等的字符串有多少个,
遍历n个字符串。
代码1
将其转化成数字0~25,放到一个二维的int数组里面来写。
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
using namespace std;
const int N = 100001;
long long cnt;
int T;
int s[26][26];
int main() {
scanf("%d", &T);
while (T--) {
cnt = 0;
memset(s, 0, sizeof(s));
int n;
scanf("%d", &n);
while (n--) {
getchar();
char a, b;
scanf("%c%c", &a, &b);
a -= 'a', b -= 'a';
for (int i = 0; i < 26; i++)
for (int j = 0; j < 26; j++)
if ((i != a) + (j != b) == 1) //某个字符串和ab只有一个字符不相等
cnt += s[i][j];
s[a][b]++;
}
printf("%lld\n", cnt);
}
return 0;
}
代码2
map来写,枚举每一种情况并且统计
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
using namespace std;
const int N = 100001;
long long cnt;
int T;
int main() {
scanf("%d", &T);
while (T--) {
map<string, int> mp;
vector<string> s(N);
int n;
cnt = 0;
scanf("%d", &n);
for (int i = 0; i < n; i++)
cin >> s[i], mp[s[i]]++;
for (int i = 0; i < n; i++) {
// string t = s[i];
for (int j = 0; j < 2; j++) {
string t = s[i];// 必须定义在这个里面,因为j变化的时候要让t恢复到和s[i]一样,这样方便下面修改第二个字符
for (char k = 'a'; k <= 'k'; k++) {
t[j] = k;
if (t != s[i])
cnt += mp[t];
}
}
}
printf("%lld\n", cnt / 2);// 这几个字符串会重复,所以要除2
}
return 0;
}
版权声明
本文为[Changersh]所创,转载请带上原文链接,感谢
https://blog.csdn.net/Changersh/article/details/124356387
边栏推荐
- Houdini > rigid body, rigid body breaking RBD
- 聊聊接口幂等与消费幂等的本质
- Intranet security attack and defense: a practical guide to penetration testing (6): domain controller security
- 访问数据库的时候出现错误 Operation not allowed for a result set of type ResultSet.TYPE_FORWARD_ONLY.详解
- Research on system and software security (I)
- Chapter V investment real estate
- Houdini流体>>粒子流体导出到unity笔记
- 内网渗透系列:内网隧道之icmpsh
- TA notes of Zhuang understand (zero) < bedding and learning methods >
- BUUCTF [ACTF2020 新生赛]Include1
猜你喜欢

Buctf MISC brossage

SAP GUI安全性

Unity C single case mode learning review notes

How does Apache Hudi accelerate traditional batch mode?

Intranet penetration series: icmptunnel of Intranet tunnel (Master James Barlow's)

Chapter IV intangible assets

随笔(不定时更新)

Towords Open World Object Detection

VBA appelle SAP RFC pour réaliser la lecture et l'écriture des données

SAP sto with billing process and configuration
随机推荐
VBA calls SAP RFC to read & write data
CTF攻防世界刷题51-
【编程实践/嵌入式比赛】嵌入式比赛学习记录(一):TCP服务器和web界面的建立
读书笔记
How to present your digital portfolio: suggestions from creative recruiters
Expression related to month, year and day in SVG
Research on system and software security (2)
strcat()、strcpy()、strcmp()、strlen()
内网渗透系列:内网隧道之icmpsh
feign如何集成hystrix
Using lambda expression to solve the problem of C file name sorting (whether it is 100 or 11)
Link to some good tutorials or notes about network security and record them
upload-labs 靶场练习
Intranet penetration series: dnscat2 of Intranet tunnel
Research on software security based on NLP (I)
MySQL——第一章节(MySQL中的数据类型)
Simplify exporting to SVG data files and all images in SVG folder
Chapter VII asset impairment
CTF-MISC学习之从开始到放弃
Research on system and software security (5)