首页 > 其他分享 >Codeforces Round #843 (Div. 2)

Codeforces Round #843 (Div. 2)

时间:2023-01-11 19:56:07浏览次数:71  
标签:843 NO int Codeforces Limit return Div define

题目链接

A

tag:构造,分类讨论
核心思路
我们其实可以发现我们要是分很多情况去讨论a b c,这题就不好做。所以我们可以假设a和b就是我们字符串的两个端点,这样题目就很好做了

  • (a='a'&&b'b')||(a'b'&&b=='a')
  • a'a'&&b'a'
  • a'b'&&b'a'
    这个题目也就解决了,所以当遇到情况很复杂的时候,我们可以抽离出最小的一种情况分类讨论,特别是这种构造类型的题目。
// Problem: A1. Gardener and the Capybaras (easy version)
// Contest: Codeforces - Codeforces Round #843 (Div. 2)
// URL: https://codeforces.com/contest/1775/problem/A1
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define NO {puts("NO") ; return ;}
#define YES {puts("YES") ; return ;}
void solve()
{
	string s;
	cin>>s;
	int last=s.size()-1;
	if((s[0]=='a'&&s[last]=='b')||(s[0]=='b'&&s[last]=='a'))
	{
		int idx=-1;
		for(int i=1;i<last;i++)
		{
			if(s[i]=='a')
			{
				idx=i;
				break;
			}
		}
		if(idx==-1)
		{
			for(int i=1;i<last;i++)
			{
				if(s[i]=='b')
				{
					idx=i;
					break;
				}
			}
		for(int i=0;i<idx;i++)
		cout<<s[i];
		cout<<" ";
		for(int i=idx;i<last;i++)
		cout<<s[i];
		cout<<" "<<s[last]<<endl;
		}
		else
		{
			for(int i=0;i<idx;i++)
			cout<<s[i];
			cout<<" "<<s[idx]<<" ";
			for(int i=idx+1;i<=last;i++)
			cout<<s[i];
			cout<<endl;	
		}
	}
	else if(s[0]=='a'&&s[last]=='a')
	{
		int idx=-1;
		for(int i=1;i<last;i++)
		{
			if(s[i]=='b')
			idx=i;
		}
		if(idx!=-1)
		{
			for(int i=0;i<idx;i++)
			cout<<s[i];
			cout<<" "<<s[idx]<<" ";
			for(int i=idx+1;i<=last;i++)
			cout<<s[i];
			cout<<endl;
		}
		else
		{
			cout<<s[0]<<" ";
		for(int i=1;i<last;i++)
		cout<<s[i];
		cout<<" "<<s[last]<<endl;
		}
	}
	else if(s[0]=='b'&&s[last]=='b')
	{
		int idx=-1;
		for(int i=1;i<last;i++)
		{
			if(s[i]=='a')
			idx=i;
		}
		if(idx!=-1)
		{
			for(int i=0;i<idx;i++)
			cout<<s[i];
			cout<<" "<<s[idx]<<" ";
			for(int i=idx+1;i<=last;i++)
			cout<<s[i];
			cout<<endl;
		}
		else
		{
			cout<<s[0]<<" ";
		for(int i=1;i<last;i++)
		cout<<s[i];
		cout<<" "<<s[last]<<endl;
		}
	}
}
int main()
{
int T;
cin>>T;
while(T--)
{
	solve();
}
}

B

tag:贪心
核心思路
首先可以发现一个很明显的性质,那就是只要一个序列是另外一个序列的子序列,那么这个就肯定是可以构造出来的。所以我们干脆直接构造出来最大的一个序列,这就需要我们使用mp存储每个数出现的次数了。
然后我们把所有的子序列拼装在一起,再for一边每一个最小的字串。如果出现了mp中某个数的次数为1,就说明肯定是不可以的。

// Problem: B. Gardener and the Array
// Contest: Codeforces - Codeforces Round #843 (Div. 2)
// URL: https://codeforces.com/contest/1775/problem/B
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define NO {puts("NO") ; return ;}
#define YES {puts("YES") ; return ;}
int n,m;
const int N=1e6;
map<int,int> p;
int vis[N];
void solve()
{
	p.clear();
	cin>>m;
			vector<vector<int>> a(m);
	for(int i=0;i<m;i++)
	{
		cin>>n;
		for(int j=0;j<n;j++)
		{
			int x;
			cin>>x;
			a[i].push_back(x);
			p[x]++;
		}
		
	}
	for(int i=0;i<m;i++)
	{
			int flag=1;
		for(auto c:a[i])
		{
			if(p[c]==1)
			flag=0;
		}
		if(flag)
		{
			YES;
		}
	}
	NO;
	
}
int main()
{
int T;
cin>>T;
while(T--)
{
	solve();
}
}

C

tag:位运算
核心思路
首先总结下一个惨痛的教训,那就是一定要多看别人的题解,要不然就会像我一样在这上面浪费两三个小时。
这题数据很大,而且有&。所以我们首先想到位运算。所以我们接下来分析下每一位。假设n中的第k位为nk,x中的第k为xk.

  • nk=0,xk=0.我们可以知道这种情况对我们的m没有影响。
  • nk=0,xk=1.这个情况是不可能实现的。
  • nk=1.xk=0.所以m必须要等到这个数位出现0之后才可以出现,也就是[temp,正无穷].
  • nk=0,xk=1.所以m必须要等到某个数为0之前出现,也就是[n,temp).
    他妈的,终于懂了。
    temp的求法可以学习下。
// Problem: C. Interesting Sequence
// Contest: Codeforces - Codeforces Round #843 (Div. 2)
// URL: https://codeforces.com/contest/1775/problem/C
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define NO {puts("NO") ; return ;}
#define YES {puts("YES") ; return ;}
#define endl "\n"
void solve()
{
	LL n,x;
	cin>>n>>x;
	LL l=n,r=5e18;
	for(int i=0;i<4;i++)
	{
		int a=n>>i&1,b=x>>i&1;
		if(a==0&&b==1)
		{
			cout<<-1<<endl;
			return;
		}
		LL temp=(n/(1LL<<i)+1)*(1LL<<i);
		if(a==1&&b==0)
		{
			l=max(l,temp);
		}
		else if(a==1&&b==1)
		{
			r=min(r,temp-1);
		}
		
	}
	cout<<(l<=r?l:-1)<<endl;
}
int main()
{
int T;
cin>>T;
while(T--)
{
	solve();
}
}

E

tag:思维
核心思路:我们首先可以挖掘这个操作的性质,也就是他其实是对我们任选的一个区间,对于区间里面的不连续的数进行操作。因为我们最后就是然我们数组的前缀和变为0,所以我们也就是讨论前缀和,其实我们结合这个性质,可以得出来

  • 如果是正数,也就是求我们正数前缀和最大的变为了0的操作数
  • 如果是负数,也就是求我们负数的前缀和变为0的操作数。
// Problem: E. The Human Equation
// Contest: Codeforces - Codeforces Round #843 (Div. 2)
// URL: https://codeforces.com/contest/1775/problem/E
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define NO {puts("NO") ; return ;}
#define YES {puts("YES") ; return ;}
#define endl "\n"
const int N=1e6+10;
LL a[N],sum[N];
void solve()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		sum[i]=sum[i-1]+a[i];
	}
	LL l=0,r=0;
	for(int i=1;i<=n;i++)
	{
		l=max(l,sum[i]);
		r=min(r,sum[i]);
	}
	cout<<l-r<<endl;
}

int main()
{
int T;
cin>>T;
while(T--)
{
	solve();
}
}

标签:843,NO,int,Codeforces,Limit,return,Div,define
From: https://www.cnblogs.com/xyh-hnust666/p/17044768.html

相关文章

  • Codeforces Round #843 (Div. 2) Problem C
    C.InterestingSequencetimelimitpertest1secondmemorylimitpertest256megabytesinputstandardinputoutputstandardoutput  Petyaandhisfr......
  • Codeforces 1278 F Cards 增强版 题解 (斯特林数,推式子)
    原题链接增强版链接增强版中k=1e7为啥网上题解的式子都那么长啊.jpg首先令\(p=\frac1m\)。求某个数的次幂的题通常都是无脑转下降幂:\(x^k=\sum_{i=0}^kS_2(k,i)x^{\u......
  • Codeforces Round #823 (Div. 2)
    A.B.C.DCodeforcesRound#823(Div.2)A.Planets-签到题意题意是一些卫星在一些轨道上,操作1花费1摧毁一个卫星,操作2花费\(y\)摧毁一个轨道上的所有卫星,问摧......
  • 「Codeforces」寒假训练 2023 #4
    A.Coprime原题链接#include<bits/stdc++.h>usingnamespacestd;typedeflonglongll;constintN=2e5+10;intt,n,ans;map<int,int>mp;intgcd(intu,......
  • Educational Codeforces Round 1
    Problem-A-Codeforcesvoidsolve(){ios;intt;cin>>t;while(t--){intn;cin>>n;intsum=n*(n+......
  • 一个CF1775C(Codeforces Round #843 (Div. 2))的小技巧
    若\(n\)的第\(i\)位为\(1\),而我们需要不断令\(n+1\)找到下一个最小的\(k\),使得\(k\)的第\(i\)位为\(0\)。技巧:假设\(n\)为10101[1]1001,括号内是要求的第\(i\)位那么先......
  • CF Codeforces Round #843 (Div. 2)
    CodeforcesRound#843(Div.2)本次脑袋不大灵光,一方面可能是怕掉分。另一方面就是交的人实在是太少了,导致我一直不敢交,其实这场cf没有我想象中那么难,甚至来说我一直是......
  • CF843记录
    正序开题A直接做完整版,一开始读错题了以为是任意字符串,想出来之后回去看题,发现只有ab,写了140+行的分讨,20:00才过。B又读错题以为是异或,想了一会儿发现读错题了,水题......
  • Educational Codeforces Round 141
    目录写在前面ABCDEF写在最后写在前面比赛地址:https://codeforces.com/contest/1783。CF车队翻车咯,本来上大分,喜提skippedA如果所有数均相等则无解。否则先降序排序......
  • Codeforces Round #843 (Div. 2) 做题记录
    CodeforcesRound#843(Div.2)做题记录A1&A2.GardenerandtheCapybarasProblemCF1775A2GardenerandtheCapybaras题目大意:给你一个由a和b组成的字符串,要......