Codeforces Round #800 (Div. 2)A-D

A、Creep

瞎搞,发现0101,最后剩下的差值的绝对值一定是最小的

#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<int,int>PII;
const int M=2e5+5;
int a[M];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int T;cin>>T;
	while(T--)
	{
		int n,m;cin>>n>>m;
		int f=1;
		while(n||m)
		{
			if(f)
			{
				cout<<"0";
				if(m)f=0;
				n--;
			}
			else{
				cout<<"1";
				m--;
				if(n)f=1;
			}
		}
		cout<<"\n";
	}
	return 0;
}

B、Paranoid String

双指针,记得开ll

#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int>PII;
const int M=2e6+5;
int a[M];
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int T;cin>>T;
	while(T--)
	{
		int n;cin>>n;
		char x[M];cin>>x+1;
		int l=1,r=1;
		int ans=n;
		while(r<=n)
		{
			if(x[l]!=x[r])ans+=r-1,l=r;
			r++;
		}
		cout<<ans<<"\n";
	}
	return 0;
}

C、Directional Increase
倒着模拟一下

#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int>PII;
const int M=2e6+5;
int a[M],now[M];
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int T;cin>>T;
	while(T--)
	{
		int n;cin>>n;
		for(int i=1;i<=n;i++)cin>>a[i],now[i]=0;
		int r=n;bool flag=1;
		while(a[r]==0&&r)r--;
		for(int i=1;i<r;i++)now[i]++;
		
		while(r){
			if(now[r]<=a[r]&&r!=1)flag=0;
			if(r==1&&now[r]!=a[r])flag=0;
			now[r-1]+=now[r]-a[r]-1;

			r--;
		}
		if(flag==0)cout<<"No\n";else cout<<"Yes\n";
	}
	return 0;
}
 

D、Fake Plastic Trees
从叶子结点开始往上做,叶子节点必定会+1,之后就是看从路径上某一个点到叶子节点的所有点的总和是否满足大于该节点的最小范围l,满足的话继续向上模拟,不满足的话就说明需要开一条新的到这个节点的路径,使得这个节点满足大于最小范围l的条件。

#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int>PII;
const int M=2e5+5;
int a[M],ans;
vector<int>v[M];
int l[M],r[M];
void dfs(int u)
{
	int s=0;
	for(int i=0;i<v[u].size();i++)
	{
		int j=v[u][i];
		dfs(j);
		s+=a[j];
	}
	if(s>=l[u])a[u]=min(r[u],s);
	else {
		ans++;
		a[u]=r[u];
	}
}
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int T;cin>>T;
	while(T--)
	{
		ans=0;
		int n;cin>>n;
		for(int i=2;i<=n;i++){
			int t;cin>>t;
			v[t].push_back(i);
		}
		for(int i=1;i<=n;i++)cin>>l[i]>>r[i];
		dfs(1);
		for(int i=1;i<=n;i++)a[i]=0,v[i].clear();
		cout<<ans<<"\n";
	}
	return 0;
}

后面没补

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值