Codeforces Round #671 (Div. 2) C. Killjoy

C. Killjoy
Description

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 x. Its rating is constant. There are n accounts except hers, numbered from 1 to n. The i-th account’s initial rating is ai. 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 n 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 t (1≤t≤100) — the number of test cases. The next 2t lines contain the descriptions of all test cases.

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

The second line of each test case contains n integers a1,a2,…,an (−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
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
1
0
2
Note

In the first test case it’s possible to make all ratings equal to 69. First account’s rating will increase by 1, and second account’s rating will decrease by 1, 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 4.

题意: 这个题目的题意好难读懂,看了网上大佬的对题意的解释才会。killjoy现在是个感染者,有n 个用户他们都有着各自的评分,现在感染规则为:若有用户的评分与感染者的评分相同,则也被感染,并无法恢复。感染时间可发生在比赛中或比赛后。killjoy可以进行codeforces比赛(killjoy不能参加),可以对用户进行任意的分数操控,但所有总和必须为0。问Killjoy最少需要进行多少场比赛才能感染所有人。

题解: 由于killjoy不能参加比赛,所以他只能在赛前和赛后感染别人。特殊的一点,在比赛过程中分数是可以不断变化的,过程中你想加多少分就加多少分,但最后总和必须是0。OK,我们知道这些就可以来分析了。

  • 如果n个人的评分都是x,那么不需要进行比赛就可以直接感染了。
  • 如果n个人的评分总和平均值为x,那么我们只要进行一场比赛就可以让所有人的评分都变为x。进行一场比赛,将他们的分数都变成x(因为均值为x,所以他们变化前后的和为0),再进行感染。
  • 如果n个人中存在一个或多个评分为x的人,那么在比赛前killjoy就可以感染他们,这样有什么用呢?那么在一场比赛中,这些人就可以感染其他所有人。(想法是未感染人评分先变为x,感染之后再变为原评分。这样总和是不变的。)
  • 如果都不是,那么我们可以先进行一场比赛使其变成第三种情况,然后自然可以达成效果。所以需要两场。

情况分析完之后,则此题易解。

以上参考自:https://blog.csdn.net/hzf0701/article/details/108708019?utm_medium=distribute.pc_relevant.none-task-blog-title-1&spm=1001.2101.3001.4242

c++ AC 代码

#include<cstdio>
#include<cstdlib>
#include<iostream>
typedef long long ll;
using namespace std;

int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		ll n,x;
		scanf("%lld%lld",&n,&x);
		ll arr[n];
		ll sum = 0, cnt = 0;
		for(int i=0;i<n;i++)
		{
			scanf("%lld",&arr[i]);
			if(arr[i] == x)
				cnt++;
			sum += arr[i] - x;
		}
		if(cnt == n)
			puts("0");
		else if(cnt >= 1 || sum == 0)
			puts("1");
		else
			puts("2");
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值