D - Game on a Graph

在这里插入图片描述

Output

For each test case output one line containing one integer. If the 1st group wins, output “1” (without quotes); If the 2nd group wins, output “2” (without quotes).

Sample Input

3
5
11212
4 6
0 1
0 2
0 3
1 2
1 3
2 3
5
11121
5 7
0 2
1 3
2 4
0 3
1 2
3 2
4 1
3
121
4 3
0 1
0 2
1 3

Sample Output

2
1
2

题意:给你一个连通图,按照给定的次序开始割边,谁先让图不连通谁就输了,给定的次序可以循环(这个地方当时没读懂,就gg了)。

思路,不用看连通图的位置,只需要看他有几个点几条边就行,如果把一个连通图分开,把他的边割到n-1条。分析它的必败态,如果割到了只剩下 n-1条边(n个点) 这个时候轮到谁割谁就输。如果边的条数正好等于n-1条,那么谁第一个割,谁就必败。本题结束。

AC代码:

#include<iostream>
using namespace std;
typedef long long ll;
int main()
{
	ll t;
	cin>>t;
	while(t--)
	{
		ll k,n,m;
		string s;
		cin>>k;
		cin>>s;
		cin>>n>>m;
		for(int i=0;i<m;i++)
		{
			ll l,r;
			cin>>l>>r;
		}
		if(n>m)
		{
			if(s[0]=='1')
				cout<<"2"<<endl;
			else	
				cout<<"1"<<endl;
			continue;
		}	
		ll num=(m-n+1)%k;
		if(s[num]=='1')
			cout<<"2"<<endl;
		else	
			cout<<"1"<<endl;	
	}
	return 0;
 } 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

aaHua_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值