CF 1419C Stairs (思考题)

C. Killjoy

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

A new agent called Killjoy invented a virus COVID-2069 that infects accounts on Codeforces. Each account has a rating, described by an integer (it can possibly be negative or very large).

Killjoy's account is already infected and has a rating equal to xx. Its rating is constant. There are nn accounts except hers, numbered from 11 to nn. The ii-th account's initial rating is aiai. Any infected account (initially the only infected account is Killjoy's) instantly infects any uninfected account if their ratings are equal. This can happen at the beginning (before any rating changes) and after each contest. If an account is infected, it can not be healed.

Contests are regularly held on Codeforces. In each contest, any of these nn accounts (including infected ones) can participate. Killjoy can't participate. After each contest ratings are changed this way: each participant's rating is changed by an integer, but the sum of all changes must be equal to zero. New ratings can be any integer.

Find out the minimal number of contests needed to infect all accounts. You can choose which accounts will participate in each contest and how the ratings will change.

It can be proven that all accounts can be infected in some finite number of contests.

Input

The first line contains a single integer tt (1≤t≤100)(1≤t≤100) — the number of test cases. The next 2t2t lines contain the descriptions of all test cases.

The first line of each test case contains two integers nn and xx (2≤n≤1032≤n≤103, −4000≤x≤4000−4000≤x≤4000) — the number of accounts on Codeforces and the rating of Killjoy's account.

The second line of each test case contains nn integers a1,a2,…,ana1,a2,…,an (−4000≤ai≤4000)(−4000≤ai≤4000) — the ratings of other accounts.

Output

For each test case output the minimal number of contests needed to infect all accounts.

Example

input

Copy

3
2 69
68 70
6 4
4 4 4 4 4 4
9 38
-21 83 50 -59 -77 15 -71 -78 20

output

Copy

1
0
2

Note

In the first test case it's possible to make all ratings equal to 6969. First account's rating will increase by 11, and second account's rating will decrease by 11, so the sum of all changes will be equal to zero.

In the second test case all accounts will be instantly infected, because all ratings (including Killjoy's account's rating) are equal to 44.

 

题解:先考虑将n-1个用户感染,显然,我们将n-1个用户的排名改变值总和sum加到第n个人身上,那么n-1个人都能被感染,这需要1轮操作。第2轮只需把第n个人的排名改变值随便加到其余某个人身上即可(因为n-1个人都已经感染,排名改变没有影响)。

实际上只有三种情况,当所有初始值都等于x时,答案显然为0;当至少有一个初始就被感染时,即初始值等于x,答案为1,因为当某个人被感染后它的排名改变没有影响,其他人的改变值都可以加到他身上;当初始值的平均值为x时,答案为1;其余情况都为2。

 

#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	for (int tt=1;tt<=t;tt++)
	{
		int last,sum=0,n,k,flag=0;
		cin>>n>>k;
		for (int i=1;i<=n;i++)
		{
			int x;
			cin>>x;
			flag+=int(x==k);
			sum+=(x-k);
			last=x;
		}
		if (flag==n) cout<<0<<endl;
		else if (flag>0) cout<<1<<endl;
		else if (sum==0) cout<<1<<endl;
		else cout<<2<<endl;

	}
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值