蒟蒻来讲题,还望大家喜。若哪有问题,大家尽可提!
Hello, 大家好哇!本初中生蒟蒻讲解一下AtCoder Beginner Contest 295这场比赛的A-D题!
===========================================================================================
You are given N N N strings W 1 , W 2 , … , W N W_1,W_2,\dots,W_N W1,W2,…,WN consisting of lowercase English letters.
If one or more of these strings equal and
, not
, that
, the
, or you
, then print Yes
; otherwise, print No
.
N N N is an integer between 1 1 1 and 100 100 100, inclusive.
1 ≤ ∣ W i ∣ ≤ 50 1 \le |W_i| \le 50 1≤∣Wi∣≤50 ( ∣ W i ∣ |W_i| ∣Wi∣ is the length of W i W_i Wi.)
W i W_i Wi consists of lowercase English letters.
The input is given from Standard Input in the following format:
N N N
W 1 W_1 W1 W 2 W_2 W2 … \dots … W N W_N WN
Print the answer.
10
in that case you should print yes and not no
Yes
We have, for instance, W 4 = W_4= W4= you
, so you should print Yes
.
10
in diesem fall sollten sie no und nicht yes ausgeben
No
None of the strings W i W_i Wi equals any of and
, not
, that
, the
, and you
.
呜呜呜,太简单
#include
#include
#include
#define endl '\n'
#define psb(i) push_back(i)
#define ppb() pop_back()
#define psf(i) push_front(i)
#define ppf() pop_front()
#define ps(i) push(i)
using namespace std;
typedef pair<int, int> PII;
string cmp[6] = {"and", "not", "that", "the", "you"};
inline int read()
{
int w = 1, s = 0;
char c = getchar();
while (c < '0' || c > '9')
{
if (c == '-') w = -1;
c = getchar();
}
while (c >= '0' && c <= '9') s = s * 10 + c - '0', c = getchar();
return w * s;
}
int main()
{
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int n;
string c;
cin >> n;
while (n --)
{
cin >> c;
for (int i = 0; i < 5; i ++)
if (c == cmp[i])
{
cout << "Yes" << endl;
return 0;
}
}
cout << "No" << endl;
return 0;
}
We have a board with R R R rows running horizontally and C C C columns running vertically. Let ( i , j ) (i,j) (i,j) denote the square at the i i i-th row from the top and j j j-th column from the left.
You are given characters B i , j B_{i,j} Bi,j representing the current states of ( i , j ) (i,j) (i,j).
.
represents an empty square; #
represents a square with a wall; 1
, 2
, … \dots …, 9
represent a square with a bomb of power 1 , 2 , … , 9 1,2,\dots,9 1,2,…,9, respectively.
At the next moment, all bombs will explode simultaneously.
When a bomb explodes, every square whose Manhattan distance from the square with the bomb is not greater than the power of the bomb will turn into an empty square.
Here, the Manhattan distance from ( r 1 , c 1 ) (r_1,c_1) (r1,c1) to ( r 2 , c 2 ) (r_2,c_2) (r2,c2) is ∣ r 1 − r 2 ∣ + ∣ c 1 − c 2 ∣ |r_1-r_2|+|c_1-c_2| ∣r1−r2∣+∣c1−c2∣.
Print the board after the explosions.
1 ≤ R , C ≤ 20 1\leq R,C \leq 20 1≤R,C≤20
R R R and C C C are integers.
Each B i , j B_{i,j} Bi,j is one of .
, #
, 1
, 2
, … \dots …, 9
.
The input is given from Standard Input in the following format:
R R R C C C
B 1 , 1 B 1 , 2 … B 1 , C B_{1,1}B_{1,2}\dots B_{1,C} B1,1B1,2…B1,C
⋮ \vdots ⋮
B R , 1 B R , 2 … B R , C B_{R,1}B_{R,2}\dots B_{R,C} BR,1BR,2…BR,C
Print R R R lines representing the board after the explosions. Use the format used in the input (do not print R R R or C C C).
4 4
.1.#
###.
.#2.
#.##
…#
#…
…
#…
The explosion of the bomb at ( 1 , 2 ) (1,2) (1,2) will turn the blue squares and purple squares in the above figure into empty squares.
The explosion of the bomb at ( 3 , 3 ) (3,3) (3,3) will turn the red squares and purple squares in the above figure into empty squares.
As seen in this sample, the explosion ranges of bombs may overlap.
2 5
…#.#
###.#
…#.#
###.#
There may be no bombs.
2 3
11#
…
…#
4 6
#.#3#.
###.#.
##.###
#1…#.
…
#…
#…#
…#.
我们直接四重循环,先循环每个炸弹,再循环能炸到的点。
#include
#include
#include
#define endl '\n'
#define psb(i) push_back(i)
#define ppb() pop_back()
#define psf(i) push_front(i)
#define ppf() pop_front()
#define ps(i) push(i)
using namespace std;
typedef pair<int, int> PII;
const int N = 2e1 + 10;
int n, m;
char a[N][N];
inline int read()
{
int w = 1, s = 0;
char c = getchar();
while (c < '0' || c > '9')
{
if (c == '-') w = -1;
c = getchar();
}
while (c >= '0' && c <= '9') s = s * 10 + c - '0', c = getchar();
return w * s;
}
int main()
{
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
cin >> n >> m;
for (int i = 1; i <= n; i ++)
for (int j = 1; j <= m; j ++)
cin >> a[i][j];
for (int x1 = 1; x1 <= n; x1 ++)
for (int y1 = 1; y1 <= m; y1 ++)
{
if (!isdigit(a[x1][y1])) continue;
int t = a[x1][y1] - '0';
for (int x2 = 1; x2 <= n; x2 ++)
for (int y2 = 1; y2 <= m; y2 ++)
if ((!isdigit(a[x2][y2]) || (x1 == x2 && y1 == y2)) && abs(x1 - x2) + abs(y1 - y2) <= t)
a[x2][y2] = '.';//, printf("(%d, %d)->(%d, %d)\n", x1, y1, x2, y2);
}
for (int i = 1; i <= n; i ++)
{
for (int j = 1; j <= m; j ++)
cout << a[i][j];
cout << endl;
}
return 0;
}
You have N N N socks. The color of the i i i-th sock is A i A_i Ai.
You want to perform the following operation as many times as possible. How many times can it be performed at most?
Choose two same-colored socks that are not paired yet, and pair them.
1 ≤ N ≤ 5 × 1 0 5 1\leq N \leq 5\times 10^5 1≤N≤5×105
1 ≤ A i ≤ 1 0 9 1\leq A_i \leq 10^9 1≤Ai≤109
All values in the input are integers.
The input is given from Standard Input in the following format:
N N N
A 1 A_1 A1 A 2 A_2 A2 … \dots … A N A_N AN
Print an integer representing the answer.
6
4 1 7 4 1 4
2
You can do the operation twice as follows.
Choose two socks with the color 1 1 1 and pair them.
Choose two socks with the color 4 4 4 and pair them.
Then, you will be left with one sock with the color 4 4 4 and another with the color 7 7 7, so you can no longer do the operation.
There is no way to do the operation three or more times, so you should print 2 2 2.
1
158260522
0
10
295 2 29 295 29 2 29 295 2 29
4
直接看看有多少个重复的颜色就行~~~
#include
#include
#include
#include
#define endl '\n'
#define psb(i) push_back(i)
#define ppb() pop_back()
#define psf(i) push_front(i)
#define ppf() pop_front()
#define ps(i) push(i)
using namespace std;
typedef pair<int, int> PII;
const int N = 5e5 + 10;
int n;
int a[N];
unordered_map<int, int> cnt;
inline int read()
{
int w = 1, s = 0;
char c = getchar();
while (c < '0' || c > '9')
{
if (c == '-') w = -1;
c = getchar();
}
while (c >= '0' && c <= '9') s = s * 10 + c - '0', c = getchar();
return w * s;
}
int main()
{
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
cin >> n;
for (int i = 1; i <= n; i ++)
cin >> a[i], cnt[a[i]] ++;
int res = 0;
for (auto c : cnt)
res += (c.second / 2);
cout << res << endl;
return 0;
}
The string 20230322
can be rearranged into 02320232
, which is a repetition of 0232
twice.
Similarly, a string consisting of digits is said to be happy when it can be rearranged into (or already is) a repetition of some string twice.
You are given a string S S S consisting of digits. Find the number of pairs of integers ( l , r ) (l,r) (l,r) satisfying all of the following conditions.
1 ≤ l ≤ r ≤ ∣ S ∣ 1 \le l \le r \le |S| 1≤l≤r≤∣S∣. ( ∣ S ∣ |S| ∣S∣ is the length of S S S.)
The (contiguous) substring formed of the l l l-th through r r r-th characters of S S S is happy.
S S S is a string consisting of digits whose length is between 1 1 1 and 5 × 1 0 5 5 \times 10^5 5×105, inclusive.
The input is given from Standard Input in the following format:
S S S
Print an integer representing the answer.
20230322
4
We have S = S= S= 20230322
.
Here are the four pairs of integers ( l , r ) (l,r) (l,r) that satisfy the condition: ( 1 , 6 ) (1,6) (1,6), ( 1 , 8 ) (1,8) (1,8), ( 2 , 7 ) (2,7) (2,7), and ( 7 , 8 ) (7,8) (7,8).
0112223333444445555556666666777777778888888889999999999
185
S S S may begin with 0
.
3141592653589793238462643383279502884197169399375105820974944
9
本题主要意思是有多少个区间满足区间内的值随便排列能够组成两个相同的序列。例如:202303
,就可以排列成230230
,这就是一个满足条件的序列!通过观察,要想凑出两个相同的小序列,必须序列中的每一个数出现的次数都是偶数,这样才能平均的分配到两个小序列中。
知道这一点之后,明确一下本题的目标:找到有多少个区间其中的数出现的次数都是偶数,这里我们可以用到异或(这一篇写的很好,值得一看)。因为,每一个数只能取1-9,所以我们用一个01序列来表示他们的奇偶(0表示偶数,1表示奇数)。
例如:S=20230322
R[i]表示前i个数中每个数出现的次数的奇偶
i = 0 0000000000
i = 1 0010000000
i = 2 1010000000
i = 3 1000000000
i = 4 1001000000
i = 5 0001000000
i = 6 0000000000
i = 7 0010000000
i = 8 0000000000
若 R i = R j ( i < j ) R_i = R_j(i < j) Ri=Rj(i<j),则从 i + 1 i+1 i+1到 j j j一定是一个满足条件的序列。
证明:从 i + 1 i + 1 i+1到 j j j的奇偶性序列通过前缀和的思想,其实就是 R j − R i ( R j ≥ R i ) R_j - R_i(R_j \geq R_i) Rj−Ri(Rj≥Ri)(注意不是i+1, 因为要取i+1),若 R j − R i R_j - R_i Rj−Ri中所有的数全部是偶数,那么序列中的体现就是0000000000
,也就是 R j − R i = 0 R_j - R_i = 0 Rj−Ri=0,即: R i = R j R_i = R_j Ri=Rj,则从 i + 1 i+1 i+1到 j j j一定是一个满足条件的序列。
所以找到所有的 R i = R j R_i = R_j Ri=Rj的个数,即为答案!
#include
#include
#include
#include
#define endl '\n'
#define int long long
#define psb(i) push_back(i)
#define ppb() pop_back()
#define psf(i) push_front(i)
#define ppf() pop_front()
#define ps(i) push(i)
using namespace std;
typedef pair<int, int> PII;
string s;
unordered_map<int, int> times;
int state;
int res = 0;
inline int read()
{
int w = 1, s = 0;
char c = getchar();
while (c < '0' || c > '9')
{
if (c == '-') w = -1;
c = getchar();
}
while (c >= '0' && c <= '9') s = s * 10 + c - '0', c = getchar();
return w * s;
}
signed main()
{
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
cin >> s;
times[0] = 1; //全是0就是一种可行的方案!
for (int i = 0; i < (int)s.size(); i ++)
{
state ^= (1 << (s[i] - '0')); //我们可以通过二进制来存储奇偶性序列
res += times[state]; //每一次加上之前的所有可以的,因为对于每一个小于j的i,都要记录
times[state] ++; //出现了一次,不断累加
}
cout << res << endl;
return 0;
}
今天就到这里了!
大家有什么问题尽管提,我都会尽力回答的!
吾欲您伸手,点的小赞赞。吾欲您喜欢,点得小关注!
(这两天比赛有点多,直到现在才发出来,非常抱歉~~~)