佛山市建设行政主管部门网站,网站怎样做地理位置定位,安卓开发菜鸟教程,全球搜和外贸快车哪个好https://codeforces.com/contest/2045/problem/A
思路#xff1a;
由于Y有两种选择#xff0c;NG也是#xff0c;那我们可以枚举以下情况#xff1a;选i个Y做辅音#xff0c;j个NG做辅音
然后贪心选择最长的即可#xff0c;观察到S最长为5000#xff0c;即使是也不会…https://codeforces.com/contest/2045/problem/A
思路
由于Y有两种选择NG也是那我们可以枚举以下情况选i个Y做辅音j个NG做辅音
然后贪心选择最长的即可观察到S最长为5000即使是也不会超时
具体解释在代码中
代码
#include iostream
#include algorithm
#includecstring
#includecctype
#includestring
#include set
#include vector
#include cmath
#include queue
#include unordered_set
#include map
#include unordered_map
#include stack
#include memory
using namespace std;
#define ll long long
#define yes cout YES endl
#define no cout NO endlmapchar,int cnt;void solve()
{string s;cin s;for (char c : s) cnt[c];int ans 0;for (int i 0; i cnt[Y]; i) {//用j个NGfor (int j 0; j min(cnt[N], cnt[G]); j) {int vcnt i cnt[A] cnt[O] cnt[E] cnt[I] cnt[U];int ccnt s.size() - vcnt - j;//减j是因为NG将NG合并了所以会少一个辅音int wcnt min(vcnt, ccnt / 2);ans max(ans, wcnt * 3 min(2 * wcnt, j));//用了j个NG每一个NG都会多奉献一个长度//min(2*wcnt,j)指的是在 选的 2*wcnt 个辅音中能有多少个NG}}cout ans endl;
}int main()
{//cin.tie(0)-sync_with_stdio(false);int t 1;//cin t;while (t--){solve();}return 0;
}