首页 > 其他分享 >每日一道思维题——CF1742F - Smaller

每日一道思维题——CF1742F - Smaller

时间:2023-02-07 13:12:19浏览次数:39  
标签:思维 Smaller int tcnt cin long scnt ch CF1742F

题意:

存在字符串s,t(初始使都为"a"),有1,2两种操作方式

1.将s后面+d个字符串x

2.将t后面+d个字符串x

操作完成后,询问是否可以改变字符串s,t 中字符顺序,使得s字典序小于 t

若可,输出 YES,否则输出 NO

思路:

由于初始是 'a',当 t 中还存在除了 'a' 之外其他字母时,构建 t 时可以将其他字母放在前面,所以输出 YES

当 t 只有字母 'a' 构成时,若 s 除了 'a' 之外还有其他字母构成输出 NO,

否则,说明 s,t 都由 'a' 构成,当 s 长度小于 t 的长度时,输出 YES, 当 s 长度大于等于 t 的长度时,输出 NO

 

代码:

#include<iostream> #include<cstring> using namespace std; int scnt[30], tcnt[30]; int main() {        ios::sync_with_stdio(false);    cin.tie(0); cout.tie(0);
   int t;    cin >> t;    while(t--)    {         int q;         long long Ssum = 1, Tsum = 1;         cin >> q;         memset(scnt, 0, sizeof scnt);         memset(tcnt, 0, sizeof tcnt);         scnt[0] = 1;         tcnt[0] = 1;         while(q--)         {             long long op, k;             string x;             cin >> op >> k >> x;             if(op==1)             {                 long long len = x.size();                 for(int i = 0; i < len; i++)                 {                     char ch = x[i];                     if(ch>= 'A' && ch <= 'Z')   ch += 32;                     scnt[ch-'a'] = 1;                 }                 Ssum += len*k;             }else{                     long long len = x.size();                     for(int i = 0; i < len; i++)                     {                         char ch = x[i];                         if(ch>= 'A' && ch <= 'Z')   ch += 32;                         tcnt[ch-'a'] = 1;                     }                     Tsum += len*k;                 }             int l = 25, r = 25;             while(tcnt[r] == 0)   r--;             while(scnt[l] == 0)   l--;             if(r > 0)   cout << "YES\n";             else{                 if(l > 0) cout << "NO\n";                 else if(Ssum < Tsum)  cout << "YES\n";                 else cout << "NO\n";             }         }                            }         return 0; }

标签:思维,Smaller,int,tcnt,cin,long,scnt,ch,CF1742F
From: https://www.cnblogs.com/lys-blogs123/p/17098004.html

相关文章