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;
}
相关推荐
倔强的小石头_1 小时前
【C语言指南】函数指针深度解析
java·c语言·算法
Yasin Chen1 小时前
C# Dictionary源码分析
算法·unity·哈希算法
_Coin_-3 小时前
算法训练营DAY27 第八章 贪心算法 part01
算法·贪心算法
董董灿是个攻城狮7 小时前
5分钟搞懂什么是窗口注意力?
算法
Dann Hiroaki7 小时前
笔记分享: 哈尔滨工业大学CS31002编译原理——02. 语法分析
笔记·算法
qqxhb9 小时前
零基础数据结构与算法——第四章:基础算法-排序(上)
java·数据结构·算法·冒泡·插入·选择
FirstFrost --sy10 小时前
数据结构之二叉树
c语言·数据结构·c++·算法·链表·深度优先·广度优先
森焱森10 小时前
垂起固定翼无人机介绍
c语言·单片机·算法·架构·无人机
搂鱼11451411 小时前
(倍增)洛谷 P1613 跑路/P4155 国旗计划
算法
Yingye Zhu(HPXXZYY)11 小时前
Codeforces 2021 C Those Who Are With Us
数据结构·c++·算法