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;
}
相关推荐
Yingjun Mo20 分钟前
1. 统计推断-基于神经网络与Langevin扩散的自适应潜变量建模与优化
人工智能·神经网络·算法·机器学习·概率论
地平线开发者1 小时前
征程 6 | 灰度图部署链路介绍
算法·自动驾驶
地平线开发者1 小时前
手撕大模型|KVCache 原理及代码解析
算法·自动驾驶
共享家95272 小时前
经典动态规划题解
算法·leetcode·动态规划
Pluchon2 小时前
硅基计划3.0 Map类&Set类
java·开发语言·数据结构·算法·哈希算法·散列表
☼←安于亥时→❦3 小时前
PyTorch之张量创建与运算
人工智能·算法·机器学习
子豪-中国机器人3 小时前
枚举算法和排序算法能力测试
开发语言·c++·算法
qiuyunoqy3 小时前
基础算法之二分算法 --- 2
算法
爱干饭的boy4 小时前
手写Spring底层机制的实现【初始化IOC容器+依赖注入+BeanPostProcesson机制+AOP】
java·数据结构·后端·算法·spring
二哈不在线4 小时前
代码随想录二刷之“动态规划”~GO
算法·golang·动态规划