本文最后更新于48 天前,其中的信息可能已经过时,如有错误请发送邮件到big_fw@foxmail.com
题意已经很清楚了就不说了。
本题有一个关键条件可以注意:可以重新排列 s 和 t 的字符。
根据这个条件以及s和t初始都为‘a’可知,如果希望s的字典序严格小于t,那么只需要让s的首字母为‘a’,t首字母为除‘a’以外的其他字法便可,因为‘a’在字典序中最小。
每次进行操作时查看t中是否含有除‘a’以外的其他字符,若含有直接输出 YES,若不含有则考虑一下情况:
s中含有其他字符:这种情况下t中全是‘a’,不可能严格大于s 输出NO
s和t都不含有其他字符:判断长度即可,若t的长度不小于等于s,输出YES,否则输出NO
以下题解
#include<bits/stdc++.h>
using namespace std;
#define int long long
string s = "a";
string t = "a";
bool isa(string arr)
{
for (int i = 0; i < arr.size(); i++)
{
if (arr[i] != 'a')
return 0;
}
return 1;
}
void resolve()
{
s = "a";
t = "a";
int q;
cin >> q;
bool sa = 1;
bool ta = 1;
int scnt = 1, tcnt = 1;
while (q--)
{
int a, b;
string c;
cin >> a >> b >> c;
bool flag = isa(c);
if (sa && ta && flag)
{
if (a == 1)
scnt += b * (int)c.size();
else
tcnt += b * (int)c.size();
if (tcnt <= scnt)
cout << "NO" << endl;
else
cout << "YES" << endl;
continue;
}
if (!flag)
{
if (a == 1)
sa = 0;
else
ta = 0;
}
if (!ta)
{
cout << "YES" << endl;
continue;
}
cout << "NO" << endl;
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin >> T;
while (T--)
resolve();
}








