蒟蒻来讲题,还望大家喜。若哪有问题,大家尽可提!
Hello, 大家好哇!本初中生蒟蒻讲解一下AtCoder Beginner Contest 299这场比赛的A-E题!
===========================================================================================
A - Treasure Chest
原题
Problem Statement
You are given a string SSS of length NNN consisting of three kinds of characters: ., |, and .
SSS contains exactly two | and exactly one .
Determine whether the is between the two |, and if so, print in; otherwise, print out.
More formally, determine whether one of the characters before the is | and one of the characters after the * is |.
Constraints
3≤N≤1003\leq N\leq 1003≤N≤100
NNN is an integer.
SSS is a string of length NNN consisting of ., |, and .
SSS contains exactly two |.
SSS contains exactly one .
Input
The input is given from Standard Input in the following format:
NNN
SSS
Output
Print a single line containing in if the * is between the two |, and out otherwise.
Sample Input 1
10
.|..*...|.
Sample Output 1
in
Between the two |, we have |……|, which contains , so you should print in.
Sample Input 2
10
.|..|.*...
Sample Output 2
out
Between the two |, we have |…|, which does not contain *, so you should print out.
Sample Input 3
3
|*|
Sample Output 3
in
题目大意
给定一个字符串SSS,如果*在两个|之间,输出in,反之输出out
思路
可以依次枚举,枚举的同时记录出现|的次数,当出现*时,若|出现的次数为1,则输出in,反之输出out。
代码
#include <iostream>
#include <cstring>
#include <algorithm>
#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;
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 s;
cin >> n >> s;
int shu = 0;
for (auto c : s)
if (c == '|') shu ++; //记录|出现的次数
else if (c == '*') //出现了*
{
if (shu == 1) cout << "in" << endl; //说明在两个|之间
else cout <<"out" << endl; //反之,就是外面
return 0;
}
return 0;
}
B - Trick Taking
原题
Problem Statement
NNN players with ID numbers 1,2,…,N1, 2, \ldots, N1,2,…,N are playing a card game.
Each player plays one card.
Each card has two parameters: color and rank, both of which are represented by positive integers.
For i=1,2,…,Ni = 1, 2, \ldots, Ni=1,2,…,N, the card played by player iii has a color CiC_iCi and a rank RiR_iRi.
All of R1,R2,…,RNR_1, R_2, \ldots, R_NR1,R2,…,RN are different.
Among the NNN players, one winner is decided as follows.
- If one or more cards with the color TTT are played, the player who has played the card with the greatest rank among those cards is the winner.
- If no card with the color TTT is played, the player who has played the card with the greatest rank among the cards with the color of the card played by player 111 is the winner. (Note that player 111 may win.)
Print the ID number of the winner.
Constraints
2≤N≤2×1052 \leq N \leq 2 \times 10^52≤N≤2×105
1≤T≤1091 \leq T \leq 10^91≤T≤109
1≤Ci≤1091 \leq C_i \leq 10^91≤Ci≤109
1≤Ri≤1091 \leq R_i \leq 10^91≤Ri≤109
i≠j ⟹ Ri≠Rji \neq j \implies R_i \neq R_ji=j⟹Ri=Rj
All values in the input are integers.
Input
The input is given from Standard Input in the following format:
NNN TTT
C1C_1C1 C2C_2C2 …\ldots… CNC_NCN
R1R_1R1 R2R_2R2 …\ldots… RNR_NRN

文章介绍了几个在AtCoder编程比赛中涉及到的字符串处理问题,包括判断星号是否在竖线之间、卡牌游戏的赢家决策以及寻找最长的dango字符串。同时,文章详细阐述了解题思路和代码实现,涉及二分查找、动态规划等算法。此外,还讨论了一个基于距离限制的图染色问题,即在满足特定距离条件下,如何为图的节点染色。
155

被折叠的 条评论
为什么被折叠?



