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

115 篇文章 3 订阅
42 篇文章 2 订阅

A. Creep

思路:01插孔放

#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
#define x first
#define y second
#define LL long long 
#define int LL
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define PII pair<int,int>
#define ll_INF 0x7f7f7f7f7f7f7f7f
#define INF 0x3f3f3f3f
#define debug(x) cerr << #x << ": " << x << endl
#define io ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
LL Mod(LL a,LL mod){return (a%mod+mod)%mod;}
LL lowbit(LL x){return x&-x;}//最低位1及其后面的0构成的数值
LL qmi(LL a,LL b,LL mod) {LL ans = 1; while(b){ if(b & 1) ans = ans * (a % mod) % mod; a = a % mod * (a % mod) % mod; b >>= 1;} return ans; }
int _;
int a,b;
void solve()
{
	cin>>a>>b;
	int c=min(a,b);
	if(a<b)
	{
		for(int i=1;i<=c;i++)cout<<"10";
		for(int i=1;i<=b-c;i++)cout<<"1";
	}
	else
	{
		for(int i=1;i<=c;i++)cout<<"01";
		for(int i=1;i<=a-c;i++)cout<<"0";
	}
	cout<<endl;
}
signed main()
{
	io;
	cin>>_;	
	while(_--)
	solve();
	return 0;
}

B. Paranoid String

思路:逆向思维,以两个相邻相同元素结尾的子段不成立,总方案减去即可

#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
#define x first
#define y second
#define LL long long 
#define int LL
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define PII pair<int,int>
#define ll_INF 0x7f7f7f7f7f7f7f7f
#define INF 0x3f3f3f3f
#define debug(x) cerr << #x << ": " << x << endl
#define io ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
LL Mod(LL a,LL mod){return (a%mod+mod)%mod;}
LL lowbit(LL x){return x&-x;}//最低位1及其后面的0构成的数值
LL qmi(LL a,LL b,LL mod) {LL ans = 1; while(b){ if(b & 1) ans = ans * (a % mod) % mod; a = a % mod * (a % mod) % mod; b >>= 1;} return ans; }
int _;
int n;
void solve()
{
	cin>>n;
	string s;
	cin>>s;
	int sum=n*(n+1)/2;
	for(int i=1;i<n;i++)
		if(s[i]==s[i-1])sum-=i;
	cout<<sum<<endl;
		
}
signed main()
{
	io;
	cin>>_;	
	while(_--)
	solve();
	return 0;
}

C. Directional Increase

最后一个不为0的数一定是负数(长度大于1)
数组前缀和一定为0
最后一个负数最大
否则不满足

#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
#define x first
#define y second
#define LL long long 
#define int LL
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define PII pair<int,int>
#define ll_INF 0x7f7f7f7f7f7f7f7f
#define INF 0x3f3f3f3f
#define debug(x) cerr << #x << ": " << x << endl
#define io ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
LL Mod(LL a,LL mod){return (a%mod+mod)%mod;}
LL lowbit(LL x){return x&-x;}//最低位1及其后面的0构成的数值
LL qmi(LL a,LL b,LL mod) {LL ans = 1; while(b){ if(b & 1) ans = ans * (a % mod) % mod; a = a % mod * (a % mod) % mod; b >>= 1;} return ans; }
int _;
int n;
const int N=2e5+10;
int s[N];
void solve()
{
	memset(s,0,sizeof s);
	cin>>n;
	vector<int>v(n+1);
	for(int i=1;i<=n;i++)
	{
		cin>>v[i];
		s[i]=s[i-1]+v[i];
	}
	bool f=false;
	int idx=1;
	for(int i=n;i;i--)
		if(v[i])
		{
			idx=i;
			break;
		}
	if(s[n])f=true;
	for(int i=1;i<=n;i++)
	{
		if(s[i]<=0&&i!=idx)f=true;
		else if(i==idx)break;
	}
	if(f)cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
}
signed main()
{
	io;
	cin>>_;	
	while(_--)
	solve();
	return 0;
}

D. Fake Plastic Trees

叶子节点必须操作一次
贪心

#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
#define x first
#define y second
#define LL long long 
#define int LL
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define PII pair<int,int>
#define ll_INF 0x7f7f7f7f7f7f7f7f
#define INF 0x3f3f3f3f
#define debug(x) cerr << #x << ": " << x << endl
#define io ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
LL Mod(LL a,LL mod){return (a%mod+mod)%mod;}
LL lowbit(LL x){return x&-x;}//最低位1及其后面的0构成的数值
LL qmi(LL a,LL b,LL mod) {LL ans = 1; while(b){ if(b & 1) ans = ans * (a % mod) % mod; a = a % mod * (a % mod) % mod; b >>= 1;} return ans; }
int _;
int n;
const int N=1e6+10;
int h[N],e[N],ne[N],w[N],idx;
int l[N],r[N];
int res;
void add(int a,int b)
{
	e[idx]=b,ne[idx]=h[a],h[a]=idx++;
}
int dfs(int u,int fa)
{
	int s=0;
	for(int i=h[u];~i;i=ne[i])
	{
		int j=e[i];
		if(j==fa)continue;
		s+=dfs(j,u);
	}
	if(h[u]==-1)
	{
		res++;
		return r[u];
	}
	if(s>=r[u])return r[u];
	if(s>=l[u]) return s;
	res++;
	return r[u];
}
void solve()
{
	cin>>n;
	idx=0;
	res=0;
	memset(h,-1,sizeof h);
	for(int i=2;i<=n;i++)
	{
		int x;
		cin>>x;
		add(x,i);
	}
	for(int i=1;i<=n;i++)cin>>l[i]>>r[i];
	dfs(1,-1);
	cout<<res<<endl;
}
signed main()
{
	io;
	cin>>_;	
	while(_--)
	solve();
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

leimingzeOuO

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

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

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

打赏作者

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

抵扣说明:

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

余额充值