ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

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

2020-11-25 23:28:51  阅读:268  来源: 互联网

标签:rating account Codeforces accounts each infected Div Killjoy


outputstandard 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 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
inputCopy
3
2 69
68 70
6 4
4 4 4 4 4 4
9 38
-21 83 50 -59 -77 15 -71 -78 20
outputCopy
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.

这题主要是题意有些许难懂 (可能对我来说)
如果全部相同 那当然不需要次数 0 即可
否则 则计算每个值ai 和 期望x 的差距总值 如果值为0 只需要次数1

如果值不为0 则将n - 1个数都换成 x ,再更新剩下的换成x 需要两步
特别的 如果其中有个剩下的 等于x 则不需要再更新了 只需要一步即可

#include <bits/stdc++.h>

using namespace std;

#define LL long long

int main(){
    int t;

    cin >> t;

    while(t --){
        int n , x;
        cin >> n >> x;
        
        vector <int> a(n);

        for(int i = 0;i < n;i ++){
            cin >> a[i];
        }

        LL sum = 0;
        bool flag = 0,is_in = 0;

        for(int i = 0;i < n;i ++){
            sum += a[i] - x;
            if(a[i] == x){
                is_in = 1;
            }
            if(a[i] != x){
                flag = 1;
            }
        }

        int res = 0;
        if(!flag){
            res = 0;
        }else if(sum == 0 || is_in){
            res = 1;
        }else{
            res = 2;
        }

        cout << res << '\n';
    }
    return 0;
}

标签:rating,account,Codeforces,accounts,each,infected,Div,Killjoy
来源: https://blog.csdn.net/weixin_44144278/article/details/110150698

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有