Codeforces Round 915 (Div. 2)

A. Constructive Problems

看了一眼数据,猜测可能是n,m里的最大

image

#include<bits/stdc++.h>
using namespace std;
void solve(){
	int a,b;
	cin>>a>>b;
	int ans=max(a,b);
	cout<<ans<<"\n";
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int t=1;
	cin>>t;
	for(int i=1;i<=t;i++)solve();
	return 0;
} 

image

ahhhhh

B. Begginer's Zelda

题意:给定一棵树,你可以的操作是选择两个节点,将两个节点中间的所有节点(包括)变成一个节点,问你最少操作多少次能将树变成一个节点。

image

大概想了一下,应该是叶子节点的个数/2向上取整

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
vector<int>a[N];
int vis[N];
int cnt=0;
void dfs(int x){
	if(vis[x])return;
	vis[x]=1;
	if(a[x].size()==1)cnt++;
	for(auto c:a[x]){
		dfs(c);
	}
}
void solve(){
	int n;
	cin>>n;
	cnt=0;
	for(int i=1;i<=n;i++){
		a[i].clear();
		vis[i]=0;
	}
	for(int i=1;i<=n-1;i++){
		int u,v;
		cin>>u>>v;
		a[u].push_back(v);
		a[v].push_back(u);
	}
	dfs(1);
	int ans=(cnt+1)/2;
	cout<<ans<<"\n";
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int t=1;
	cin>>t;
	for(int i=1;i<=t;i++)solve();
	return 0;
} 

本文作者:yufan1102

本文链接:https://www.cnblogs.com/yufan1102/p/17908989.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   yufan1102  阅读(80)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~
点击右上角即可分享
微信分享提示
💬
评论
📌
收藏
💗
关注
👍
推荐
🚀
回顶
收起
  1. 1 404 not found REOL
404 not found - REOL
00:00 / 00:00
An audio error has occurred.