【补题日记】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;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

cls1277

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

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

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

打赏作者

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

抵扣说明:

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

余额充值