补题日记CF#749 Div.1+ Div.2

Posted cls1277

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了补题日记CF#749 Div.1+ Div.2相关的知识,希望对你有一定的参考价值。

Pro

Codeforces Round #749 (Div. 1 + Div. 2, based on Technocup 2022 Elimination Round 1)

Sol

A. Windblume Ode

分析可得,满足条件的子集大小为n个或n-1个。

所以具体做法为:枚举集合中的每一个数,判断删除后是否可以组成合数,如果可以即为答案。

简单证明:若集合总和为偶数,则必为合数;若总和为奇数,因为奇数=偶数+奇数,则减去一个奇数后必为偶数,即合数。

或者还可以直接判断差值是否为合数。

B. Omkar and Heavenly Tree

思路比较巧妙,思维题。

找b中没有出现过的点做根节点,然后对于每一个查询,都把a和c与根节点相连。

这样就保证了不会有b在a和c的路径上。

C. Omkar and Determination

很容易想到,是否能唯一确定取决于中间是否包含一列不含“关键点”的列,称之为“关键列”。

关键点:上面和左面都是X的点。用vector和bool可以稍微节省一下空间。

然后维护前缀和,对于每个查询只需要看区间内“关键列”的个数是否为0。

注意区间左右端点,因为区间长度至少为2,所以l列不予考虑,直接用sum[r]-sum[l]即可。

Code

A. Windblume Ode

//By cls1277
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<stack>
#include<sstream>
#include<set>
#include<cassert>
#include<bitset>
using namespace std;
typedef long long LL;
#define PI acos(-1)
#define INF 2147483647
#define eps 1e-7
#define Fo(i,a,b) for(LL i=(a); i<=(b); i++)
#define Ro(i,b,a) for(LL i=(b); i>=(a); i--)
#define Eo(i,x,_) for(LL i=head[x]; i; i=_[i].next)
#define Ms(a,b) memset((a),(b),sizeof(a))
#define lowbit(_) _&(-_)
#define mk(_,__) make_pair(_,__)
#define pii pair<int,int>
#define ls x<<1
#define rs x<<1|1
#define endl '\\n'
inline LL read() {
	LL x = 0, f = 1;char c = getchar();
	while (!isdigit(c)) { if (c == '-')f = -f;c = getchar(); }
	while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48ll), c = getchar();
	return x * f;
}

const LL maxn = 105;
int sum,a[maxn];

bool isp(int x) {
	Fo(i,2,sqrt(x))
		if(x%i==0)
			return 0;
	return 1;
}

int main() {
	ios::sync_with_stdio(false);
	#ifdef DEBUG
	freopen("data.txt","r",stdin);
	#endif
	int T; cin>>T;
	while(T--) {
		int n; cin>>n; sum=0;
		Fo(i,1,n) cin>>a[i],sum+=a[i];
		if(!isp(sum)) {
			cout<<n<<endl;
			Fo(i,1,n) cout<<i<<" ";
			cout<<endl;
			continue;
		}
		Fo(i,1,n)
			if(a[i]%2) {
			//if(!isp(sum-a[i])) {
				cout<<n-1<<endl;
				Fo(j,1,n) {
					if(i==j) continue;
					cout<<j<<" ";
				}
				cout<<endl;
				break;
			}
	}
	return 0;
}

B. Omkar and Heavenly Tree

//By cls1277
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<stack>
#include<sstream>
#include<set>
#include<cassert>
#include<bitset>
using namespace std;
typedef long long LL;
#define PI acos(-1)
#define INF 2147483647
#define eps 1e-7
#define Fo(i,a,b) for(LL i=(a); i<=(b); i++)
#define Ro(i,b,a) for(LL i=(b); i>=(a); i--)
#define Eo(i,x,_) for(LL i=head[x]; i; i=_[i].next)
#define Ms(a,b) memset((a),(b),sizeof(a))
#define lowbit(_) _&(-_)
#define mk(_,__) make_pair(_,__)
#define pii pair<int,int>
#define ls x<<1
#define rs x<<1|1
#define endl '\\n'
inline LL read() {
	LL x = 0, f = 1;char c = getchar();
	while (!isdigit(c)) { if (c == '-')f = -f;c = getchar(); }
	while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48ll), c = getchar();
	return x * f;
}

const LL maxn = 1e5+5;

int main() {
	ios::sync_with_stdio(false);
	#ifdef DEBUG
	freopen("data.txt","r",stdin);
	#endif
	int T; cin>>T;
	while(T--) {
		bitset<maxn>vis;
		int n,m,p; cin>>n>>m;
		Fo(i,1,m) {
			int a,b,c; cin>>a>>b>>c;
			vis[b]=1;
		}
		Fo(i,1,n)
			if(!vis[i]) {
				p=i;
				break;
			}
		Fo(i,1,n) {
			if(i==p) continue;
			cout<<p<<" "<<i<<endl;
		}
	}
	return 0;
}

C. Omkar and Determination

//By cls1277
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<stack>
#include<sstream>
#include<set>
#include<cassert>
#include<bitset>
using namespace std;
typedef long long LL;
#define PI acos(-1)
#define INF 2147483647
#define eps 1e-7
#define Fo(i,a,b) for(LL i=(a); i<=(b); i++)
#define Ro(i,b,a) for(LL i=(b); i>=(a); i--)
#define Eo(i,x,_) for(LL i=head[x]; i; i=_[i].next)
#define Ms(a,b) memset((a),(b),sizeof(a))
#define lowbit(_) _&(-_)
#define mk(_,__) make_pair(_,__)
#define pii pair<int,int>
#define ls x<<1
#define rs x<<1|1
#define endl '\\n'
inline LL read() {
	LL x = 0, f = 1;char c = getchar();
	while (!isdigit(c)) { if (c == '-')f = -f;c = getchar(); }
	while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48ll), c = getchar();
	return x * f;
}

const LL maxn = 1e6+5;
vector<bool>mp[maxn];
int n,m,sum[maxn];
bitset<maxn>vis;

int main() {
	ios::sync_with_stdio(false);
	#ifdef DEBUG
	freopen("data.txt","r",stdin);
	#endif
	cin>>n>>m;
	Fo(i,1,n)
		Fo(j,1,m) {
			char x; cin>>x;
			if(x=='.') mp[i].push_back(false);
			if(x=='X') mp[i].push_back(true);
		}
	Fo(i,2,n) {
		for(int j=1; j<mp[i].size(); j++) {
			if(vis[j+1]) continue;
			if(mp[i-1][j]==true&&mp[i][j-1]==true) vis[j+1]=1;
		}
	}
	Fo(i,1,m) sum[i]=sum[i-1]+vis[i];
	int q; cin>>q;
	while(q--) {
		int a,b; cin>>a>>b;
		if(sum[b]-sum[a])	cout<<"NO"<<endl;
		else cout<<"YES"<<endl;
	}	
	return 0;
}

以上是关于补题日记CF#749 Div.1+ Div.2的主要内容,如果未能解决你的问题,请参考以下文章

CodeforcesRound#749(Div.1+Div.2,basedonTechnocup2022EliminationRound1)-B. Omkar and Heavenly Tree-题解

Codeforces Round #749(Div. 1+Div. 2, based on Technocup 2022 Elimination Round1)-A. Windblume Ode-题解

补题日记CF#748 Div.3

补题日记CF#744 Div.3 & 2020 ICPC沈阳站

CodeforcesRound#749(Div.1.2basedonTechnocup2022EliminationRound1)-D.Omkar and the Meaning of Life-题解

Codeforces Round #749 (Div. 1 + Div. 2, based on Technocup 2022 Elimination Round 1) ABCD解题报告