0
点赞
收藏
分享

微信扫一扫

Codeforces Round #833 (Div. 2) A--B

minute_5 2022-11-13 阅读 99



A

思路:直接盲猜x/2上取整。

应该写成(x + 1) / 2最好



#include <bits/stdc++.h>
#define endl '\n'
using namespace std;




void s(){
int n;
cin >> n;
cout << (n + 1) / 2 << endl;
}

int main(){
cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);

int t;
cin >> t;
while(t--) s();


return 0;
}


 


B

Codeforces Round #833 (Div. 2) A--B_字符串


大意:

给你0--9组成的字符串。询问这些字符串的子串满足条件的情况有多少个。

条件:字串中,不一样的数字种类>=最多的数字个数


思路:0--9数字,最多的情况就是100. 因此暴力枚举当前字符作为头的子串,子串的长度为当前字符往后100个字符。


代码:


#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

void s(){
int n;
cin >> n;
string a;
cin >> a;


long long ans = 0;
for(int i = 0; i < a.size(); i ++){
for(int j = i; j < i + 100 && j < a.size(); j ++){
int book[11] = {};
int dicnt = 0, maxcnt = 0;
for(int k = i; k < j + 1; k ++){
if(book[a[k] - '0'] == 0) dicnt ++, book[a[k] - '0'] ++;
else maxcnt = max( ++ book[a[k] - '0'] , maxcnt);
}
if(maxcnt <= dicnt) ans++;
}
}

cout << ans << endl;
}

int main(){
cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);

int t;
cin >> t;
while(t-- ) s();


return 0;
}





举报

相关推荐

0 条评论