Codeforces Round #650 (Div. 3)(A-C)

Short Substrings CodeForces - 1367A
思路:除了第一位和最后一位之外,剩下的两个之中取一个就行。
代码如下:

#include<bits/stdc++.h>
#define ll long long
using namespace std;

const int maxx=1e5+100;
string a,b;

int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		a="";
		b="";
		cin>>a;
		b+=a[0];
		for(int i=1;i<a.length()-1;i+=2) b+=a[i];
		b+=a[a.length()-1];
		cout<<b<<endl;
	}
	return 0;
}

Even Array CodeForces - 1367B
思路:如果说奇偶数和位置的奇偶数不一致的话,就输出-1,。否则统计有多少个位置不一致,除以2就行。
代码如下:

#include<bits/stdc++.h>
#define ll long long
using namespace std;

const int maxx=50;
int a[maxx];
int n;

int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&n);
		int sumj=0,sumo=0;
		for(int i=0;i<n;i++) 
		{
			scanf("%d",&a[i]);
			if(a[i]&1) sumj++;
			else sumo++;
		}
		if(sumo!=(n+1)/2||sumj!=n/2) cout<<-1<<endl;
		else
		{
			int cnt=0;
			for(int i=0;i<n;i++)
			{
				if(i%2==a[i]%2) continue;
				else cnt++;
			}
			cout<<(cnt>>1)<<endl;
		}
	}
	return 0;
}

Social Distance CodeForces - 1367C
思路:分别统计一下“1”的个数的前缀和以及后缀和。然后从头开始遍历,如果这[i-k-1,i-1]以及[i+1,i+k+1]中没有“1”的话,就放置一个“1”。
代码如下:

#include<bits/stdc++.h>
#define ll long long
using namespace std;

const int maxx=2e5+100;
int suml[maxx],sumr[maxx];
char s[maxx];
int n,k;

int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d%d",&n,&k);
		cin>>(s+1);
		suml[0]=0;
		for(int i=1;i<=n;i++) suml[i]=suml[i-1]+(s[i]=='1');
		sumr[n+1]=0;
		for(int i=n;i>=1;i--) sumr[i]=sumr[i+1]+(s[i]=='1');
		int cnt=0;
		for(int i=1;i<=n;)
		{
			if(s[i]=='1') i++;
			else 
			{
				if(suml[i-1]-suml[max(i-k-1,0)]==0&&sumr[i+1]-sumr[min(i+k+1,n+1)]==0) 
					cnt++,i=i+k+1;
				else i++;
			}
		}
		cout<<cnt<<endl;
	}
	return 0;
}

努力加油a啊,(o)/~

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

starlet_kiss

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值