非众数 WA on #6,#7,#8,#9,#10 求条

学术版

您这有点抽象啊 我的: ```cpp #include <bits/stdc++.h> using namespace std; string s; int len = 0; unsigned long long cnt = 0; bool is_not(string si){ int a[26] = {0}; if(si.length() <= 1) return 0; for(int i = 0; i < si.length(); i ++ ) a[si[i] - 'a'] ++ ; int mx = 0; for(int i = 0; i < 26; i ++ ) mx = max(mx, a[i]); if(mx <= (si.length() / 2)) return 1; return 0; } int main(){ ios::sync_with_stdio(0); cin.tie(0); cin >> s; len = s.length(); map <string, int> ds; vector <string> v; for(int i = 0; i < len; i ++ ) for(int j = 1; i + j <= len; j ++ ) v.push_back(s.substr(i, j)); unique(v.begin(), v.end()); for(int i = 0; i < v.size(); i ++ ){ if(is_not(v[i])) cnt ++ ; } cout << cnt << '\n'; return 0; } ```
by liboya5074 @ 2024-04-19 21:12:25


@[liboya5074](/user/1049961) 我是先枚举子序列,然后判断是否是非众数串,最火判断重复的
by danlao @ 2024-04-19 21:15:26


```cpp #include <bits/stdc++.h> using namespace std; int n,ans = 0; char a[505]; bool check(int x,int y){ int cnt[50],mx = -10; memset(cnt,0,sizeof(cnt)); for (int i = x; i <= y; i++) cnt[a[i] - 'a']++; for (int i = 0; i < 30; i++) mx = max(mx,cnt[i]); if (mx <= (y - x + 1) / 2) return true; else return false; } int main(){ scanf("%s",a + 1); n = strlen(a + 1); for (int i = 1; i <= n; i++) for (int j = i; j <= n; j++) if (check(i,j)) ans++; printf("%d",ans); return 0; } ```
by liuruiqing @ 2024-04-19 21:17:02


@[yaodiguoan](/user/1023793) 不需要判重
by wjr_jok @ 2024-04-19 21:19:23


@[wjr_jok](/user/1236806) 谢谢大佬!
by danlao @ 2024-04-19 21:21:22


|