打一半说不计分了,刚好天梯赛打完就不想写了,后面不先把写过的写个题解把
Problem Statement
A
You are given a string S of length N consisting of three kinds of characters: ., |, and *. S 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≤100Nis an integer.Sis a string of lengthNconsisting of.,|, and*.Scontains exactly two|.Scontains exactly one*.
Input
The input is given from Standard Input in the following format:
N
S
Output
Print a single line containing in if the * is between the two |, and out otherwise.
代码
void solve()
{
cin >> n;
string s;
cin >> s;
int x = 0;
for(int i = 0;i < n;i ++)
{
if(s[i] == '*')
{
x = i;
}
}
for(int i = x-1;i >= 0;i --)
{
if(s[i] == '|')
f = false;
}
for(int i = x+1;i < n;i ++)
{
if(s[i] == '|')
f1 = false;
}
if(!f&&!f1)
cout << "in" << '\n';
else
cout << "out" << '\n';
}
Problem Statement
B
N players with ID numbers 1,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,…,N, the card played by player i has a color Ci and a rank Ri. All of R1,R2,…,RN are different.
Among the N players, one winner is decided as follows.
- If one or more cards with the color
Tare played, the player who has played the card with the greatest rank among those cards is the winner. - If no card with the color
Tis played, the player who has played the card with the greatest rank among the cards with the color of the card played by player11is the winner. (Note that player1may win.)
Print the ID number of the winner.
Constraints
2≤N≤2×1051≤T≤1091≤Ci≤1091≤Ri≤109i=j⟹Ri=Rj- All values in the input are integers.
void solve()
{
cin >> n >> m;
map<int,int>mp;
for(int i = 1;i <= n;i ++)
{
cin >> a[i];
}
for(int i = 1;i <= n;i ++)
{
cin >> b[i];
}
for(int i = 1;i <= n;i ++)
{
if(!mp[a[i]])
mp[a[i]] = i;
else
{
if(b[mp[a[i]]] < b[i])
mp[a[i]] = i;
}
}
if(mp[m])
cout << mp[m] << '\n';
else
cout << mp[a[1]] << '\n';
}
signed main()
{
int tt = 1;
//sc(tt);
while(tt--)
{
solve();
}
}
C
For a positive integer L, a level-L dango string is a string that satisfies the following conditions.
- It is a string of length
L+1consisting ofoand-. - Exactly one of the first character and the last character is
-, and the otherLcharacters areo.
For instance, ooo- is a level-3 dango string, but none of -ooo-, oo, and o-oo- is a dango string (more precisely, none of them is a level-L dango string for any positive integer L).
You are given a string S of length N consisting of the two characters o and -. Find the greatest positive integer X that satisfies the following condition.
- There is a contiguous substring of
Sthat is a level-Xdango string.
If there is no such integer, print -1.
Constraints
1≤N≤2×105Sis a string of lengthNconsisting ofoand-.
代码
void solve()
{
cin >> n;
string s;
cin >> s;
int ans = 0,num = 0;
for(int i = 1;i < n;i ++)
{
if(s[i] == 'o'&&s[i-1] == '-')
{
for(int j = i;j < n;j ++)
{
if(s[j] == 'o')
num++;
else
break;
}
if(i + num - 1< n)
{
ans = max(ans,num);
}
num = 0;
}
}
for(int i = 0;i < n;i ++)
{
if(s[i] == 'o')
{
num++;
}
else
{
ans = max(ans,num);
num = 0;
}
}
if(ans)
cout << ans << '\n';
else
cout << -1 << '\n';
}
signed main()
{
int tt = 1;
//sc(tt);
while(tt--)
{
solve();
}
}