The 2021 CCPC Weihai Onsite ADGJM

Dashboard - The 2021 CCPC Weihai Onsite - Codeforces

A. Goodbye, Ziyin!

思路

首先,根的度数必须 <= 2

然后,不能存在度数 > 3 的点

cpp 复制代码
#include <bits/stdc++.h>

#define int long long

constexpr int N = 1e6 + 10;
constexpr int mod = 998244353;
constexpr int Inf = 0x3f3f3f3f;

int n;
int d[N];

void solve() {
	std::cin >> n;
	for (int i = 1; i <= n - 1; i ++) {
		int u, v;
		std::cin >> u >> v;
		d[u] ++;
		d[v] ++;
	}
	int ans = 0;
	bool ok = true;
	for (int i = 1; i <= n; i ++) {
		if (d[i] <= 2) ans ++;
		if (d[i] > 3) ok = false;
	}
	if (!ok) std::cout << 0 << "\n";
	else std::cout << ans << "\n";
}
signed main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);

	int t = 1;
	while (t--) {
		solve();
	}
	return 0;
}

J. Circular Billiard Table

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define int long long 
const int mxn = 1e6+7;
int in[mxn];
void solve(){
    int a, b;
    cin >> a >> b;
    cout << (180*b/__gcd(180*b,a))-1<<'\n';
}


signed main(){
    ios::sync_with_stdio(false);cin.tie(nullptr), cout.tie(nullptr);
    int T = 1;
    cin >> T;
    while(T--) solve();
    return 0;
}
相关推荐
矛取矛求8 分钟前
日期类的实现
开发语言·c++·算法
在下雨59938 分钟前
项目讲解1
开发语言·数据结构·c++·算法·单例模式
Jayyih1 小时前
嵌入式系统学习Day36(简单的网页制作)
学习·算法
脑洞代码1 小时前
20250909的学习笔记
算法
Christo31 小时前
TFS-2003《A Contribution to Convergence Theory of Fuzzy c-Means and Derivatives》
人工智能·算法·机器学习
黑菜钟1 小时前
代码随想录第七天|● 454.四数相加II ● 383. 赎金信 ● 15. 三数之和 18.四数之和
c++·算法·leetcode
Yingjun Mo1 小时前
1. 统计推断-ALMOND收敛性分析
人工智能·算法·机器学习
海梨花2 小时前
CSP认证练习题目推荐 (1)
算法·深度优先·csp
天上的光2 小时前
大模型——剪枝、量化、蒸馏、二值化
算法·机器学习·剪枝
pzx_0013 小时前
【LeetCode】14. 最长公共前缀
算法·leetcode·职场和发展