文章目录
- A I'm a teapot
- B You're a teapot
- C Flush
- D XNOR Operation
- E Trapezium
- F We're teapots
- G Binary Operation
AtCoder Beginner Contest 418
A I’m a teapot
Takahashi is a teapot.
Since he is a teapot, he will gladly accept tea, but will refuse any other liquid.
Determine whether you can pour a liquid named SSS into him.
You are given a string SSS of length NNN consisting of lowercase English letters.
Determine whether SSS is a string that ends with tea
.
Constraints
- 1≤N≤201 \leq N \leq 201≤N≤20
- NNN is an integer.
- SSS is a string of length NNN consisting of lowercase English letters.
翻译
高桥是一个茶壶。
既然他是茶壶,他就会欣然接受茶水,而拒绝其他任何液体。
确定能否向它倒入名为 SSS 的液体。
给你一个长度为 NNN 的字符串 SSS ,由小写英文字母组成。
请判断 SSS 是否是以 tea
结尾的字符串。
约束
- 1≤N≤201 \leq N \leq 201≤N≤20
- NNN 是整数。
- SSS 是长度为 NNN 的字符串,由小写英文字母组成。
分析:判断字符的结尾是不是 tea
即可。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 10, INF = 0x3f3f3f3f;void solve() {int n; string s; cin >> n >> s;bool f = (n > 2 && s.substr(n - 3, 3) == "tea");cout << (f ? "Yes" : "No") << "\n";
}
int main() {// freopen("1.in", "r", stdin);int T = 1; while (T--) solve();return 0;
}
B You’re a teapot
I begin with T and end with T, and I am full of T. What am I?
For a string ttt, define the filling rate as follows:
- If the first and last characters of ttt are both
t
and ∣t∣≥3|t| \geq 3∣t∣≥3: Let xxx be the number oft
in ttt. Then the filling rate of ttt is x−2∣t∣−2\displaystyle\frac{x-2}{|t|-2}∣t∣−2x−2, where ∣t∣|t|∣t∣ denotes the length of ttt. - Otherwise: the filling rate of ttt is 000.
You are given a string SSS. Find the maximum possible filling rate of a substring of SSS.
What is a substring?
A substring of SSS is a string obtained by removing zero or more characters from the beginning and the end of SSS. For example,ab
,bc
, andbcd
are substrings ofabcd
, whileac
,dc
, ande
are not substrings ofabcd
.
Constraints
- 1≤∣S∣≤1001 \leq |S| \leq 1001≤∣S∣≤100
- SSS is a string consisting of lowercase English letters.
翻译
我是什么?
对于一个字符串 ttt ,定义填充率如下:
- 如果 ttt 的第一个字符和最后一个字符都是 "T "和 ∣t∣≥3|t| \geq 3∣t∣≥3 :设 xxx 是 ttt 中 "t "的个数。那么 ttt 的填充率为 x−2∣t∣−2\displaystyle\frac{x-2}{|t|-2}∣t∣−2x−2 ,其中 ∣t∣|t|∣t∣ 表示 ttt 的长度。
- 否则: ttt 的填充率为 000 。
给你一个字符串 SSS 。求 SSS 子串的最大填充率。
什么是子串?
SSS 的子串是指从 SSS 的开头和结尾删除零个或多个字符后得到的字符串。例如,ab
、bc
和bcd
是abcd
的子串,而ac
、dc
和e
不是abcd
的子串。
约束
- 1≤∣S∣≤1001 \leq |S| \leq 1001≤∣S∣≤100
- SSS 是一个由小写英文字母组成的字符串。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 10, INF = 0x3f3f3f3f;void solve() {string s; cin >> s;int x = 0, n = s.size();double ans = 0;for (int i = 0; i < n; i++)for (int j = i + 1; j < n; j++)if (s[i] == 't' && s[j] == 't') {int x = 0, len = j - i + 1;for (int k = i; k <= j; k++)x += (s[k] == 't');ans = max(ans, (x - 2.0) / (len - 2.0));}cout << fixed << setprecision(12) << ans << "\n";
}
int main() {// freopen("1.in", "r", stdin);int T = 1; while (T--) solve();return 0;
}
C Flush
On the poker table, there are tea bags of NNN different flavors. The flavors are numbered from 1 through NNN, and there are AiA_iAi tea bags of flavor iii (1≤i≤N1 \leq i \leq N1≤i≤N).
You will play a game using these tea bags. The game has a parameter called difficulty between 1 and A1+⋯+ANA_1 + \cdots + A_NA1+⋯+AN, inclusive. A game of difficulty bbb proceeds as follows:
- You declare an integer xxx. Here, it must satisfy b≤x≤A1+⋯+ANb \leq x \leq A_1 + \cdots + A_Nb≤x≤A1+⋯+AN.
- The dealer chooses exactly xxx tea bags from among those on the table and gives them to you.
- You check the flavors of the xxx tea bags you received, and choose bbb tea bags from them.
- If all bbb tea bags you chose are of the same flavor, you win. Otherwise, you lose.
The dealer will do their best to make you lose.
You are given QQQ queries, so answer each of them. The jjj-th query is as follows:
- For a game of difficulty BjB_jBj, report the minimum integer xxx you must declare at the start to guarantee a win. If it is impossible to win, report −1-1−1 instead.
Constraints
- 1≤N≤3×1051 \leq N \leq 3 \times 10^51≤N≤3×105
- 1≤Q≤3×1051 \leq Q \leq 3 \times 10^51≤Q≤3×105
- 1≤Ai≤1061 \leq A_i \leq 10^61≤Ai≤106 (1≤i≤N1 \leq i \leq N1≤i≤N)
- 1≤Bj≤min(109,A1+⋯+AN)1 \leq B_j \leq \min(10^9, A_1 + \cdots + A_N)1≤Bj≤min(109,A1+⋯+AN) (1≤j≤Q1 \leq j \leq Q1≤j≤Q)
- All input values are integers.
翻译:
在扑克桌上,有不同口味的茶包。口味从 111 到 NNN 编号,有 AiA_iAi 个茶包口味 iii(1≤i≤N1\leq i\leq N1≤i≤N)。
你将用这些茶包玩游戏。游戏有一个名为难度的参数,介于 111 和 a1+⋯+aNa_1+\cdots+a_Na1+⋯+aN 之间。难度游戏 bbb 的收益如下:
- 声明一个整数 xxx。这里,它必须满足 b≤x≤A1+⋯+ANb\leq x\leq A_1+\cdots+A_Nb≤x≤A1+⋯+AN。
- 经销商从桌上的茶包中准确地选择 xxx 个茶包,并将其送给您。
- 您检查收到的 xxx 个茶包,并从中选择 bbb 个茶包。
- 如果你选择的 bbb 个茶包都是相同的味道,你就赢了。否则,你输了。
经销商会尽最大努力让你输。
您会收到 QQQ 的查询,请逐一回答。第 jjj 个查询如下:
- 对于难度为 BjB_jBj 的游戏,报告您必须在开始时声明的最小整数 xxx,以确保获胜。如果不可能获胜,则报告 −1-1−1。
约束条件
- 1≤N≤3×1051 \leq N \leq 3 \times 10^51≤N≤3×105
- 1≤Q≤3×1051 \leq Q \leq 3 \times 10^51≤Q≤3×105
- 1≤Ai≤1061 \leq A_i \leq 10^61≤Ai≤106 (1≤i≤N1 \leq i \leq N1≤i≤N)
- 1≤Bj≤min(109,A1+⋯+AN)1 \leq B_j \leq \min(10^9, A_1 + \cdots + A_N)1≤Bj≤min(109,A1+⋯+AN) (1≤j≤Q1 \leq j \leq Q1≤j≤Q)
- 所有输入值都是整数。
分析:
本题目要模拟样例,找到题目所求:当相同元素的数量至少为 bbb 的需要最少有解数量 xxx。
解法:考虑对原数组 aia_iai 排序,求出前缀和 sis_isi,二分查询第一个≥b\ge b≥b 的元素位置 ididid,如果答案存在,则 ans=sid−1+(b−1)×(n−id+1)+1ans=s_{id-1} + (b-1) \times (n-id+1) +1ans=sid−1+(b−1)×(n−id+1)+1;否则 ans=−1ans=-1ans=−1。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 10, INF = 0x3f3f3f3f;
int n, q, a[N], b;
ll s[N];void solve() {cin >> n >> q;for (int i = 1; i <= n; i++) cin >> a[i];sort(a + 1, a + 1 + n);for (int i = 1; i <= n; i++) s[i] = s[i - 1] + a[i];while (q--) {cin >> b;int id = lower_bound(a + 1, a + 1 + n, b) - a;ll ans = -1;if (id <= n && a[id] >= b)ans = s[id - 1] + 1ll * (b - 1) * (n - id + 1) + 1;cout << ans << "\n";}
}
int main() {// freopen("1.in", "r", stdin);int T = 1; while (T--) solve();return 0;
}
D XNOR Operation
This problem is a subproblem of Problem G.
A non-empty string SSS consisting of 0
and 1
is called a beautiful string when it satisfies the following condition:
- (Condition) You can perform the following sequence of operations until the length of SSS becomes 111 and make the only character remaining in SSS be
1
.- Choose any integer iii satisfying 1≤i≤∣S∣−11 \leq i \leq |S| - 11≤i≤∣S∣−1.
- Define an integer xxx as follows:
- If Si=S_i =Si=
0
and Si+1=S_{i+1} =Si+1=0
, let x=1x = 1x=1. - If Si=S_i =Si=
0
and Si+1=S_{i+1} =Si+1=1
, let x=0x = 0x=0. - If Si=S_i =Si=
1
and Si+1=S_{i+1} =Si+1=0
, let x=0x = 0x=0. - If Si=S_i =Si=
1
and Si+1=S_{i+1} =Si+1=1
, let x=1x = 1x=1.
- If Si=S_i =Si=
- Remove SiS_iSi and Si+1S_{i+1}Si+1, and insert the digit corresponding to xxx in their place.
For example, if S=S=S=10101
and you choose i=2i=2i=2, the string after the operation is1001
.
You are given a string TTT of length NNN consisting of 0
and 1
.
Find the number of beautiful strings that are substrings of TTT. Even if two substrings are identical as strings, count them separately if they are taken from different positions.
What are substrings? A substring of SSS is a string obtained by deleting zero or more characters from the beginning and zero or more characters from the end of SSS.
For example, 10
is a substring of 101
, but 11
is not a substring of 101
.
Constraints
- 1≤N≤2×1051 \leq N \leq 2 \times 10^51≤N≤2×105
- NNN is an integer.
- TTT is a string of length NNN consisting of
0
and1
.
翻译:
本问题是问题 G 的子问题。
由 0
和 1
组成的非空字符串 SSS 满足以下条件时,称为优美字符串:
- 条件)你可以执行以下一系列操作,直到 SSS 的长度变为 111 ,并使 SSS 中唯一剩下的字符是
1
。- 选择满足 1≤i≤∣S∣−11 \leq i \leq |S| - 11≤i≤∣S∣−1 的任意整数 iii 。
- 定义整数 xxx 如下:
- 如果 Si=S_i =Si=
0
且 {98421818}0和 $S_{i+1} =$ 0
,设 x=1x = 1x=1 . - 若 Si=S_i =Si=
0
且 {56774510}0
, 则设 x=1x = 1x=1 .0和 $S_{i+1} =$ 1
,则 x=0x = 0x=0 . - 若 Si=S_i =Si=
1
,且 Si+1=S_{i+1} =Si+1=0
,则让 {12243413}.0",则 x=0x = 0x=0 . - 如果 Si=S_i =Si=
1
和 {1848987}0
, 让 {297737}.1且 $S_{i+1} =$
1`,则设 x=1x = 1x=1 。
- 如果 Si=S_i =Si=
- 删除 SiS_iSi 和 Si+1S_{i+1}Si+1 ,并插入与 xxx 相对应的数字。
例如,如果 S=S=S= 10101",而您选择了 i=2i=2i=2 ,则操作后的字符串为 “1001”。
给定长度为 NNN 的字符串 TTT 由 0
和 1
组成。
求作为 TTT 的子串的美丽字符串的个数。即使两个子串是相同的字符串,如果它们取自不同的位置,也要分别计算。
什么是子串? SSS 的子串是删除 SSS 开头的零个或多个字符和结尾的零个或多个字符后得到的字符串。
例如,10
是101
的子串,但11
不是101
的子串。
约束
- 1≤N≤2×1051 \leq N \leq 2 \times 10^51≤N≤2×105
- NNN 是整数。
- TTT 是长度为 NNN 的字符串,由
0
和1
组成。
分析:
E Trapezium
There are NNN points on a two-dimensional plane, with the iii-th point at coordinates (Xi,Yi)(X_i, Y_i)(Xi,Yi). It is guaranteed that no two points are at the same position, and no three points are collinear.
Among the combinations of four points from these points, how many combinations can form a trapezoid as a polygon with those four points as vertices?
Constraints
- 4≤N≤20004 \leq N \leq 2\,0004≤N≤2000
- 0≤Xi,Yi≤1070 \leq X_i, Y_i \leq 10^70≤Xi,Yi≤107 (1≤i≤N1 \leq i \leq N1≤i≤N)
- No two points are at the same location.
- No three points are collinear.
- All input values are integers.
翻译:
在一个二维平面上有 NNN 个点,其中第 iii 个点的坐标为 (Xi,Yi)(X_i, Y_i)(Xi,Yi) 。保证没有两个点在同一位置,也没有三个点是共线的。
在这些点的四点组合中,以这四点为顶点能组成梯形多边形的组合有多少种?
约束
- 4≤N≤20004 \leq N \leq 2\,0004≤N≤2000
- 0≤Xi,Yi≤1070 \leq X_i, Y_i \leq 10^70≤Xi,Yi≤107 ( 1≤i≤N1 \leq i \leq N1≤i≤N )
- 没有两个点在同一位置。
- 没有三个点是相邻的。
- 所有输入值均为整数。
分析:
F We’re teapots
There are NNN teapots arranged in a row, numbered from 111 to NNN from left to right.
There is a sequence of integers (a1,…,aN)(a_1, \dots, a_N)(a1,…,aN), initially with values a1=⋯=aN=−1a_1 = \dots = a_N = -1a1=⋯=aN=−1.
You will fill each teapot with either tea or coffee so that the following conditions are all satisfied:
- For any two adjacent teapots, at least one of them contains tea.
- For any integer iii satisfying 1≤i≤N1 \leq i \leq N1≤i≤N, if ai≠−1a_i \neq -1ai=−1, then exactly aia_iai of teapots 1,…,i1, \dots, i1,…,i contain coffee.
You are given QQQ queries, which you should process in the given order.
The jjj-th query (1≤j≤Q1 \leq j \leq Q1≤j≤Q) is as follows:
- Change the value of aXja_{X_j}aXj to YjY_jYj. Then, print the number, modulo 998244353998244353998244353, of ways to fill the teapots satisfying the conditions.
Constraints
- 2≤N≤2×1052 \leq N \leq 2 \times 10^52≤N≤2×105
- 1≤Q≤2×1051 \leq Q \leq 2 \times 10^51≤Q≤2×105
- 1≤Xj≤N1 \leq X_j \leq N1≤Xj≤N (1≤j≤Q1 \leq j \leq Q1≤j≤Q)
- −1≤Yj≤Xj-1 \leq Y_j \leq X_j−1≤Yj≤Xj (1≤j≤Q1 \leq j \leq Q1≤j≤Q)
- All input values are integers.
翻译
有 NNN 个茶壶排成一排,从左到右依次编号为 111 至 NNN 。
有一串整数 (a1,…,aN)(a_1, \dots, a_N)(a1,…,aN) ,最初的值为 a1=⋯=aN=−1a_1 = \dots = a_N = -1a1=⋯=aN=−1 。
你要在每个茶壶中注入茶或咖啡,以满足以下所有条件:
- 对于任意两个相邻的茶壶,其中至少有一个装有茶叶。
- 对于满足 1≤i≤N1 \leq i \leq N1≤i≤N 的任意整数 iii ,如果有 ai≠−1a_i \neq -1ai=−1 ,那么在 1,…,i1, \dots, i1,…,i 的茶壶中,正好有 aia_iai 个茶壶装有咖啡。
给你 QQQ 个查询,你应按给定的顺序处理这些查询。
jjj -th 查询( 1≤j≤Q1 \leq j \leq Q1≤j≤Q )如下:
- 将 aXja_{X_j}aXj 的值改为 YjY_jYj 。然后,打印出满足条件的茶壶的装水方式的数量,模数为 998244353998244353998244353 。
限制因素
- 2≤N≤2×1052 \leq N \leq 2 \times 10^52≤N≤2×105
- 1≤Q≤2×1051 \leq Q \leq 2 \times 10^51≤Q≤2×105
- 1≤Xj≤N1 \leq X_j \leq N1≤Xj≤N ( 1≤j≤Q1 \leq j \leq Q1≤j≤Q )
- −1≤Yj≤Xj-1 \leq Y_j \leq X_j−1≤Yj≤Xj ( 1≤j≤Q1 \leq j \leq Q1≤j≤Q )
- 所有输入值均为整数。
分析:
G Binary Operation
There are 161616 integer tuples (A,B,C,D)(A, B, C, D)(A,B,C,D) satisfying A,B,C,D∈{0,1}A, B, C, D \in \lbrace 0, 1 \rbraceA,B,C,D∈{0,1}. For each of them, solve the following problem.
A non-empty string SSS consisting of
0
and1
is called a beautiful string when it satisfies the following condition:
- (Condition) You can perform the following sequence of operations until the length of SSS becomes 111 and make the only character remaining in SSS be
1
.
- Choose any integer iii satisfying 1≤i≤∣S∣−11 \leq i \leq |S| - 11≤i≤∣S∣−1.
- Define an integer xxx as follows:
- If Si=S_i =Si=
0
and Si+1=S_{i+1} =Si+1=0
, let x=Ax = Ax=A.- If Si=S_i =Si=
0
and Si+1=S_{i+1} =Si+1=1
, let x=Bx = Bx=B.- If Si=S_i =Si=
1
and Si+1=S_{i+1} =Si+1=0
, let x=Cx = Cx=C.- If Si=S_i =Si=
1
and Si+1=S_{i+1} =Si+1=1
, let x=Dx = Dx=D.- Remove SiS_iSi and Si+1S_{i+1}Si+1, and insert the digit corresponding to xxx in their place.
For example, if S=S=S=10101
and you choose i=2i=2i=2, the string after the operation is1001
if B=0B=0B=0, and1101
if B=1B=1B=1.You are given a string TTT of length NNN consisting of
0
and1
.
- Let LLL be the length of the longest beautiful string that is a substring of TTT (if no substring of TTT is a beautiful string, let L=−1L = -1L=−1),
- Let MMM be the number of beautiful strings that are substrings of TTT.
Find LLL and MMM. Even if two substrings are identical as strings, count them separately if they are taken from different positions.
What are substrings?
A substring of SSS is a string obtained by deleting zero or more characters from the beginning and zero or more characters from the end of SSS.
For example,10
is a substring of101
, but11
is not a substring of101
.
Constraints
- 1≤N≤2×1051 \leq N \leq 2 \times 10^51≤N≤2×105
- NNN is an integer.
- TTT is a string of length NNN consisting of
0
and1
.
翻译
有 161616 个整数元组 (A,B,C,D)(A, B, C, D)(A,B,C,D) 满足 A,B,C,D∈{0,1}A, B, C, D \in \lbrace 0, 1 \rbraceA,B,C,D∈{0,1} 。请分别求解下列问题。
由 "0 "和 "1 "组成的非空字符串 SSS 满足以下条件时,称为优美字符串:
- (条件)你可以执行下面的操作序列,直到 SSS 的长度变为 111 ,并使 SSS 中唯一剩下的字符是
1
。
- 选择满足 1≤i≤∣S∣−11 \leq i \leq |S| - 11≤i≤∣S∣−1 的任意整数 iii 。
- 定义整数 xxx 如下:
- 如果 Si=S_i =Si=
0
和 {53892861}0
。0和 $S_{i+1} =$ 0
,则设 x=Ax = Ax=A .- 如果 Si=S_i =Si=
0
且 {346645525}0
, 则让 x=Ax = Ax=A .0 "和 Si+1=S_{i+1} =Si+1= “1”,设为 x=Bx = Bx=B 。- 如果 Si=S_i =Si=
1
和 {3676760}1
,令 x=Bx = Bx=B .1 “和 Si+1=S_{i+1} =Si+1= 0”,则 x=Cx = Cx=C .- 如果 Si=S_i =Si=
1
和 {66227549}0
,让 x=Cx = Cx=C .1和 $S_{i+1} =$
1.如果 $S_i =$
1和 $S_{i+1} =$
1`, 则让 x=Dx = Dx=D .
- 删除 SiS_iSi 和 Si+1S_{i+1}Si+1 ,并插入与 xxx 相对应的数字。
例如,如果 S=S=S= 10101",并选择 i=2i=2i=2 ,则操作后的字符串如果是 B=0B=0B=0 则为 “1001”,如果是 B=1B=1B=1 则为 “1101”。给出长度为 NNN 的字符串 TTT ,它由
0
和1
组成。
- 设 LLL 是长度为 TTT 的子串的最长优美字符串(如果 TTT 的子串都不是优美字符串,则设为 L=−1L = -1L=−1 )、
- 设 MMM 是作为 TTT 子串的优美字符串的个数。
找出 LLL 和 MMM 。即使两个子串是相同的字符串,如果它们取自不同的位置,也要分别计算。
什么是子串?
SSS 的子串是删除 SSS 开头的零个或多个字符和结尾的零个或多个字符后得到的字符串。
例如,10
是101
的子串,但11
不是101
的子串。
约束
- 1≤N≤2×1051 \leq N \leq 2 \times 10^51≤N≤2×105
- NNN 是整数。
- TTT 是长度为 NNN 的字符串,由
0
和1
组成。
分析: