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;
}
相关推荐
listhi5205 分钟前
压缩感知信号重构的块稀疏贝叶斯学习(BSBL)算法:原理、实现与应用
学习·算法·重构
摸个小yu6 分钟前
【力扣LeetCode热题h100】哈希、双指针、滑动窗口
算法·leetcode·哈希算法
充值修改昵称25 分钟前
数据结构基础:B+树如何优化数据库性能
数据结构·b树·python·算法
Cinema KI25 分钟前
一键定位,哈希桶的极速魔法
数据结构·c++·算法·哈希算法
曾几何时`30 分钟前
二分查找(九)2300. 咒语和药水的成功对数
数据结构·算法
We་ct1 小时前
LeetCode 12. 整数转罗马数字:从逐位实现到规则复用优化
前端·算法·leetcode·typescript
绿算技术1 小时前
重塑智算存储范式:绿算技术NVMe-oF芯片解决方案全景剖析
人工智能·算法·gpu算力
sin_hielo1 小时前
leetcode 3510
数据结构·算法·leetcode
Anastasiozzzz1 小时前
力扣hot100 20.有效的括号 解析
java·算法·面试·力扣
CrazyClaz1 小时前
负载均衡算法
算法·负载均衡