Codeforces Round #833 (Div. 2)(补)

A .

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
const int N=1e6+10,M=1e6+10;
int a[N],mp[M]={0};
int s[N],pos[N];
int go[N];
void solve(){
	int n;cin>>n;
	if((n/2)==((n-1)/2))cout<<n/2+1<<'\n';
	else cout<<n/2<<'\n';
	
}
signed main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
	int t;cin>>t;
	//int t=1;
	while(t--){
		solve();
	}
} 

B . 因为最多就有10 所以直接暴力

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
const int INF=0x3f3f3f3f;
const int N=1e6+10,M=1e6+10;
int a[N],mp[M]={0};
int cnt[N];
void solve(){
	int n;string s;cin>>n>>s;
	int ans=0;s='?'+s;
	for(int i=1;i<=n;i++){
		for(int k=0;k<=9;k++)cnt[k]=0;
		int cnt1=0,maxx=0;
		for(int j=i;j<=min(n,i+105);j++){
			cnt[s[j]-'0']++;
			if(cnt[s[j]-'0']==1)cnt1++;
			maxx=max(maxx,cnt[s[j]-'0']);
			if(maxx<=cnt1)ans++;
		}
	} 
	cout<<ans<<'\n';
}
signed main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
	int t;cin>>t;
	//int t=1;
	while(t--){
		solve();
	}
} 

C. 题意是前缀和数组里面0最多 我们只需要从后往前遍历 每次遇到a[i]==0就把a[i]更新为a[i]后面的前缀和数组中出现次数最多的数即可

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
const int INF=0x3f3f3f3f;
const int N=1e6+10,M=1e6+10;
int a[N];
int cnt[N];
void solve(){
	int n;cin>>n;int a[n+1],pre[n+1];pre[0]=0;
	for(int i=1;i<=n;i++){
		cin>>a[i];pre[i]=pre[i-1]+a[i];
	}
	map<int,int>mp;int maxx=0,ans=0;
	for(int i=n;i>=1;i--){
		mp[pre[i]]++;
		maxx=max(maxx,mp[pre[i]]);
		if(a[i]==0){
			ans+=maxx;
			maxx=0;
			mp.clear();
		}
	}
	for(int i=1;i<=n;i++){
		if(a[i]==0)break;
		if(pre[i]==0)ans++;
	}
	cout<<ans<<'\n';
}
signed main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
	int t;cin>>t;
	//int t=1;
	while(t--){
		solve();
	}
} 

D. 补数论去了 QAQ

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值