您的位置:首页 > 游戏 > 游戏 > 凡客诚品倒闭了吗知乎_品牌设计公司是做什么的_短视频获客系统_郑州网站推广

凡客诚品倒闭了吗知乎_品牌设计公司是做什么的_短视频获客系统_郑州网站推广

2024/10/9 21:35:46 来源:https://blog.csdn.net/wx20041102/article/details/142795370  浏览:    关键词:凡客诚品倒闭了吗知乎_品牌设计公司是做什么的_短视频获客系统_郑州网站推广
凡客诚品倒闭了吗知乎_品牌设计公司是做什么的_短视频获客系统_郑州网站推广

比赛链接:Dashboard - Codeforces Round 833 (Div. 2) - Codeforces

B. Diverse Substrings

题意:

思路:

当字符串长度 > 10 时,每个字符出现的次数至少是 2 次 ( 0 ~ 9 个出现一次,剩余字符出现 )

当字符串长度 > 20 时,每个字符出现的次数至少是 3 次

......

当字符串长度 > 100 时,每个字符出现的次数至少是 11 次

但是数字种类就只有 10 个 ( 0 ~ 9 ),所以当字符串长度 > 100时,一定是错误的

所以只用枚举长度在 100 以内的即可

AC代码:

#include<bits/stdc++.h>
using namespace std;
#define int long long
void solve()
{int n; cin >> n;string s; cin >> s;int ans = 0;for( int i = 0 ; i < n ; i++){int cnt[10] = { 0 };int mx = 0; int temp = 0;for( int j = i ; j < min( i + 101 , n ) ; j++ ){if( cnt[ s[j] - '0' ] == 0 ) temp++;cnt[ s[j] - '0' ]++;mx = max( mx , cnt[s[j] - '0']);if( temp >= mx )ans++;}}cout << ans << endl;
}
signed main()
{int tt; cin >> tt;while(tt--)solve();return 0;
}

C. Zero-Sum Prefixes

题意:

 

思路:(贪心)

n = 9

a =              1         0       0        1       -1         0      1       0        -1

前缀和         1         1       1        2        1         1      2        2        1

                               x        y                             z               p

   要使前缀尽量变为0 ,所以这个数就要尽量变成 [ y , z )中前缀和的众数的相反数,此时贡献最大

AC代码:

#include<bits/stdc++.h>
using namespace std;
#define int long long
void solve()
{int n; cin >> n;vector<int> a(n + 1);for( int i = 1; i <= n; i++ ) cin >> a[i];vector<int> pre(n + 1);vector<int> b;for( int i = 1; i <= n; i++){pre[i] = pre[i-1] + a[i];if( !a[i] ) b.push_back(i);}if( b.size() == 0 ) // 没有0的时候单独讨论一下{int ans = 0;for( int i = 1 ; i <= n; i++) {if( pre[i] == 0 ) ans++;}cout << ans << endl;return;}int ans = 0;for( int i = 1 ; i < b[0] ; i++)if( !pre[i] )ans++; // 在第一个0之前的前缀和有多少贡献b.push_back( n + 1 ); // 为了下面与 b[ i + 1 ]那个方便for( int i = 0 ; i < b.size() - 1 ; i++){map<int,int> mp;int mx = 0;for( int j = b[i] ; j < b[i + 1] ; j++){mp[pre[j]]++;mx = max( mx , mp[pre[j]] ); // 找众数}ans += mx;}cout << ans << endl;
}
signed main()
{int tt; cin >> tt;while(tt--)solve();return 0;
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com