[codeforces 1363C] Game On Leaves 树上分胜负

Codeforces Round #646 (Div. 2)  参与排名人数14203

[codeforces 1363C]    Game On Leaves   树上分胜负

总目录详见https://blog.csdn.net/mrcrack/article/details/103564004

在线测评地址http://codeforces.com/contest/1363/problem/C

ProblemLangVerdictTimeMemory
C - Game On Leaves GNU C++17Accepted31 ms300 KB

第一次能在赛中AC有关树的题,虽然只是C题,但也是可喜可贺。

成功AC该题之前,WA了一次,原因在于

A leaf node is a node with degree less than or equal to 1.

注意叶子节点的度可以是0,这是最特殊的情况,对应的测试数据如下

Input:
1
1 1
Output:
Ayush

再举一例

Input:
1
5 9
5 8
5 1
9 6
9 4
8 7
8 2
6 3
Output:
Ashish

最优选择如上图

很明显,若x第一次没被选中,那么最优选择对应的选择次数有n-1次,选中第n-1次的获胜。

AC代码如下

#include <cstdio>
#define maxn 1010
int n,x,d[maxn];
void init(){
	int i,u,v;
	scanf("%d%d",&n,&x);
	for(i=1;i<=n;i++)d[i]=0;
	for(i=1;i<n;i++){
		scanf("%d%d",&u,&v);
		d[u]++,d[v]++;//度的统计
	}
}
void solve(){
	int i,j;
	if(d[x]==0||d[x]==1){printf("Ayush\n");return;}//x一开始就是叶子节点
	if((n-1)%2)printf("Ayush\n");
	else printf("Ashish\n");
}
int main(){
	int t,i;
	scanf("%d",&t);
	while(t--){
		init();
		solve();
	}
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值