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

A - Windblume Ode

题意 给定一个序列 从此序列中找出一个最大数量的子集 使得这个子集的总和为合数
我们可以先计算原集合的和是合数吗 如果是则输出全部
如果不是那么它必定是奇数 序列中肯定包含大于等于1个奇数 把它去掉即可

代码

#include <bits/stdc++.h>

using namespace std;

const int N = 410;

inline int read()
{
	register int x = 0, k = 1;
	char c = getchar();
	while (c > '9' || c < '0') 
	{
		if (c == '-') k = -1;
		c = getchar();
	}
	while (c <= '9' && c >= '0')
	{
		x = (x << 1) + (x << 3) + (c ^ 48);
		c = getchar();
	}
	return x * k;
}

int n, sum;
int a[N];

inline void solve()
{
	sum = 0;
	n = read();
	for (int i = 1; i <= n; i ++ ) a[i] = read(), sum += a[i];
	bool flag = false;
	int pos = -1;

	for (int i = 2; i <= sqrt(sum); i ++ )
		if (sum % i == 0) {flag = true; break;}

	if (flag) 
	{
		cout << n <<endl;  
		for (int i = 1; i <= n; i ++ ) 
			cout << i << ' ';  
	}
	else
	{
		cout << n - 1 << endl;
	 	for (int i = 1; i <= n; i ++ ) if (a[i] & 1) pos = i;
	 	for (int i = 1; i <= n; i ++ ) if (i != pos) cout << i << ' ';
	}
	
	puts("");
}

int main()
{
	int t;
	t = read();

	while (t -- )
	{
		solve();
	}

	return 0;
}

B - Omkar and Heavenly Tree

水题 找到一个没当过中间点的点做中间点然后做菊花即可

代码

#include <bits/stdc++.h>

using namespace std;

inline int read()
{
	register int x = 0, k = 1;
	char c = getchar();
	while (c > '9' || c < '0') 
	{
		if (c == '-') k = -1;
		c = getchar();
	}
	while (c <= '9' && c >= '0')
	{
		x = (x << 1) + (x << 3) + (c ^ 48);
		c = getchar();
	}
	return x * k;
}

const int N = 1e5 + 10;

int n, m;
bool st[N];

inline void solve()
{
	memset(st, 0, sizeof st);
	n = read(), m = read();
	while (m -- )
	{
		int a, b, c;
		a = read(), b = read(), c = read();
		st[b] = true;
	}
	int pos = -1;
	for (int i = 1; i <= n; i ++ ) if (!st[i]) pos = i;
	for (int i = 1; i <= n; i ++ )
		if (i != pos) printf("%d %d\n", pos, i);
}

int main()
{
	int t;
	t = read();

	while (t -- )
	{
		solve();
	}

	return 0;
}


C - Omkar and Determination

这个题意是真的难懂 最后还是理解错了
这个题的意思是问给定一张图 然后给定q个询问 每次询问给定一个区间 问在这个区间中是否可以通过确定某个点能否逃出来判断图是否是一定的 只要找这两种即可
?X 和 ?X
XX X.
这样的是无法确定的 因为点和x都无法逃脱

代码

#include <bits/stdc++.h>

using namespace std;

inline int read()
{
	register int x = 0, k = 1;
	char c = getchar();
	while (c > '9' || c < '0') 
	{
		if (c == '-') k = -1;
		c = getchar();
	}
	while (c <= '9' && c >= '0')
	{
		x = (x << 1) + (x << 3) + (c ^ 48);
		c = getchar();
	}
	return x * k;
}

const int N = 1e6 + 10;

int n, m, q;
int st[N], sum[N];

inline void solve()
{
	scanf("%d%d", &n, &m);
	string a[2];
	for (int i = 0; i < n; i ++ ) 
	{
		cin >> a[i % 2];
		if (i == 0) continue;
		for (int j = 0; j < m; j ++ )
		{
			if (j == 0) continue;
			if (a[(i % 2) ^ 1][j] == 'X' && a[i % 2][j - 1] == 'X') 
				st[j + 1] = 1;
		}
	}
	for (int i = 1; i <= m; i ++ )
		sum[i] = (sum[i - 1] + st[i]);
	scanf("%d", &q);
	while (q -- )
	{
		int a, b;
		scanf("%d%d", &a, &b);
		int res = sum[b] - sum[a - 1];
		if (res == 1 && st[a] == 1) puts("YES");
		else if (!res) puts("YES");
		else puts("NO");
	}

}

int main()
{
	solve();
	return 0;
}


E. Moment of Bloom

这个题挺简单的 给定一个图 以及多次操作 每次操作可以把从u到v的任意一条路径的权值加一 问所有操作后是否所有路径上的权值为偶数
我们可以这样思考 每次操作给定两个点 那么必然会从两个点中一个点出来一个点进去 即度++ 那么如果最后某一个点操作了奇数次则肯定是不满足题意的 需要添加的操作也就是奇数点的二分之一
那么怎样快速的去找路径呢 我们可以把整张图看作一棵树(不一定是树) 用lca来求路径

代码

#include <bits/stdc++.h>

using namespace std;

const int N = 3e5 + 10;

inline int read()
{
	register int x = 0, k = 1;
	char c = getchar();
	while (c > '9' || c < '0') 
	{
		if (c == '-') k = -1;
		c = getchar();
	}
	while (c >= '0' && c <= '9')
	{
		x = (x << 3) + (x << 1) + (c ^ 48);
		c = getchar();
	}
	return x * k;
}

int n, m, q;
int d[N];
int dep[N], frm[N];
bool vis[N]; 
int qu[N], qv[N], pu[N], pv[N];

vector<int> G[N];

void dfs(int u, int fa, int depth)
{
	dep[u] = depth, frm[u] = fa, vis[u] = true;
	for (int i = 0; i < G[u].size(); i ++ )
	{
		int to = G[u][i];
		if (!vis[to]) dfs(to, u, depth + 1);
	}
}

void solve()
{
	n = read(), m = read();
	for (int i = 0; i < m; i ++ )
	{
		int a, b;
		a = read(), b = read();
		G[a].push_back(b), G[b].push_back(a);
	}

	dfs(1, 0, 1);

	scanf("%d", &q);
	for (int i = 1; i <= q; i ++ )
	{
		qu[i] = read(), qv[i] = read();
		d[qu[i]] ++, d[qv[i]] ++ ;
	}

	int cnt = 0;
	for (int i = 1; i <= n; i ++ ) if (d[i] & 1) cnt ++ ;
	if (cnt){
		puts("NO");
		printf("%d\n", cnt / 2);
	}
	else{
		puts("YES");
		for (int i = 1; i <= q; i ++ )
		{
			int u = qu[i], v= qv[i];
			int lu = 0, lv = 0;
			while (dep[u] > dep[v]) pu[ ++ lu] = u, u = frm[u];
			while (dep[u] < dep[v]) pv[ ++ lv] = v, v = frm[v];
			while (u != v)
			{
				pu[ ++ lu] = u, u = frm[u];
				pv[ ++ lv] = v, v = frm[v];
			}
			pu[ ++ lu] = u;
			printf("%d\n", lu + lv);
			for (int j = 1; j <= lu; j ++ ) printf("%d ", pu[j]);
			for (int j = lv; j >= 1; j -- ) printf("%d ", pv[j]);
			puts("");
		}
	}
}

int main()
{
	solve();

	return 0;
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值