309478: CF1686A. Everything Everywhere All But One

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Everything Everywhere All But One

题意翻译

你有 $n$ 个数 $a_1,a_2,\cdots,a_n$,若每次操作是将其中的 $n-1$ 个数以这 $n-1$ 个数的平均数替换(不一定是整数),那么请你判断这 $n$ 个数能否在有限次操作内全部相等?

题目描述

You are given an array of $ n $ integers $ a_1, a_2, \ldots, a_n $ . After you watched the amazing film "Everything Everywhere All At Once", you came up with the following operation. In one operation, you choose $ n-1 $ elements of the array and replace each of them with their arithmetic mean (which doesn't have to be an integer). For example, from the array $ [1, 2, 3, 1] $ we can get the array $ [2, 2, 2, 1] $ , if we choose the first three elements, or we can get the array $ [\frac{4}{3}, \frac{4}{3}, 3, \frac{4}{3}] $ , if we choose all elements except the third. Is it possible to make all elements of the array equal by performing a finite number of such operations?

输入输出格式

输入格式


The first line of the input contains a single integer $ t $ ( $ 1 \le t \le 200 $ ) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $ n $ ( $ 3 \le n \le 50 $ ) — the number of integers. The second line of each test case contains $ n $ integers $ a_1, a_2, \ldots, a_n $ ( $ 0 \le a_i \le 100 $ ).

输出格式


For each test case, if it is possible to make all elements equal after some number of operations, output $ \texttt{YES} $ . Otherwise, output $ \texttt{NO} $ . You can output $ \texttt{YES} $ and $ \texttt{NO} $ in any case (for example, strings $ \texttt{yEs} $ , $ \texttt{yes} $ , $ \texttt{Yes} $ will be recognized as a positive response).

输入输出样例

输入样例 #1

4
3
42 42 42
5
1 2 3 4 5
4
4 3 2 1
3
24 2 22

输出样例 #1

YES
YES
NO
NO

说明

In the first test case, all elements are already equal. In the second test case, you can choose all elements except the third, their average is $ \frac{1 + 2 + 4 + 5}{4} = 3 $ , so the array will become $ [3, 3, 3, 3, 3] $ . It's possible to show that it's impossible to make all elements equal in the third and fourth test cases.

Input

题意翻译

你有 $n$ 个数 $a_1,a_2,\cdots,a_n$,若每次操作是将其中的 $n-1$ 个数以这 $n-1$ 个数的平均数替换(不一定是整数),那么请你判断这 $n$ 个数能否在有限次操作内全部相等?

Output

**题意翻译**

给定n个数\(a_1, a_2, \cdots, a_n\),每次操作可以选取其中\(n-1\)个数,用这\(n-1\)个数的平均值来替换它们(平均值不一定是整数),问是否可以通过有限次操作使得这n个数全部相等?

**题目描述**

给定一个由n个整数组成的数组\(a_1, a_2, \ldots, a_n\)。在观看了令人惊叹的电影《一切无处不在》之后,你想出了以下操作。每次操作,你从数组中选择\(n-1\)个元素,并将它们替换为它们的算术平均值(这个平均值不一定是整数)。例如,从数组\([1, 2, 3, 1]\)中,如果我们选择前三个元素,可以得到数组\([2, 2, 2, 1]\),或者如果我们选择除了第三个元素之外的所有元素,可以得到数组\([\frac{4}{3}, \frac{4}{3}, 3, \frac{4}{3}]\)。问是否可以通过执行有限次这样的操作使得数组的所有元素相等?

**输入输出格式**

**输入格式**

输入的第一行包含一个整数\(t\)(\(1 \le t \le 200\))——测试用例的数量。接下来是每个测试用例的描述。

每个测试用例的第一行包含一个整数\(n\)(\(3 \le n \le 50\))——整数的数量。

每个测试用例的第二行包含\(n\)个整数\(a_1, a_2, \ldots, a_n\)(\(0 \le a_i \le 100\))。

**输出格式**

对于每个测试用例,如果在执行一定数量的操作后可以使所有元素相等,输出\(\texttt{YES}\)。否则,输出\(\texttt{NO}\)。

\(\texttt{YES}\)和\(\texttt{NO}\)的输出可以为任意大小写(例如,字符串\(\texttt{yEs}\),\(\texttt{yes}\),\(\texttt{Yes}\)都将被视为肯定回答)。

**输入输出样例**

**输入样例 #1**

```
4
3
42 42 42
5
1 2 3 4 5
4
4 3 2 1
3
24 2 22
```

**输出样例 #1**

```
YES
YES
NO
NO
```

**说明**

在第一个测试用例中,所有元素已经相等。

在第二个测试用例中,可以选择除了第三个元素之外的所有元素,它们的平均值是\(\frac{1 + 2 + 4 + 5}{4} = 3\),所以数组将变为\([3, 3, 3, 3, 3]\)。

可以证明,在第三个和第四个测试用例中,不可能使所有元素相等。**题意翻译** 给定n个数\(a_1, a_2, \cdots, a_n\),每次操作可以选取其中\(n-1\)个数,用这\(n-1\)个数的平均值来替换它们(平均值不一定是整数),问是否可以通过有限次操作使得这n个数全部相等? **题目描述** 给定一个由n个整数组成的数组\(a_1, a_2, \ldots, a_n\)。在观看了令人惊叹的电影《一切无处不在》之后,你想出了以下操作。每次操作,你从数组中选择\(n-1\)个元素,并将它们替换为它们的算术平均值(这个平均值不一定是整数)。例如,从数组\([1, 2, 3, 1]\)中,如果我们选择前三个元素,可以得到数组\([2, 2, 2, 1]\),或者如果我们选择除了第三个元素之外的所有元素,可以得到数组\([\frac{4}{3}, \frac{4}{3}, 3, \frac{4}{3}]\)。问是否可以通过执行有限次这样的操作使得数组的所有元素相等? **输入输出格式** **输入格式** 输入的第一行包含一个整数\(t\)(\(1 \le t \le 200\))——测试用例的数量。接下来是每个测试用例的描述。 每个测试用例的第一行包含一个整数\(n\)(\(3 \le n \le 50\))——整数的数量。 每个测试用例的第二行包含\(n\)个整数\(a_1, a_2, \ldots, a_n\)(\(0 \le a_i \le 100\))。 **输出格式** 对于每个测试用例,如果在执行一定数量的操作后可以使所有元素相等,输出\(\texttt{YES}\)。否则,输出\(\texttt{NO}\)。 \(\texttt{YES}\)和\(\texttt{NO}\)的输出可以为任意大小写(例如,字符串\(\texttt{yEs}\),\(\texttt{yes}\),\(\texttt{Yes}\)都将被视为肯定回答)。 **输入输出样例** **输入样例 #1** ``` 4 3 42 42 42 5 1 2 3 4 5 4 4 3 2 1 3 24 2 22 ``` **输出样例 #1** ``` YES YES NO NO ``` **说明** 在第一个测试用例中,所有元素已经相等。 在第二个测试用例中,可以选择除了第三个元素之外的所有元素,它们的平均值是\(\frac{1 + 2 + 4 + 5}{4} = 3\),所以数组将变为\([3, 3, 3, 3, 3]\)。 可以证明,在第三个和第四个测试用例中,不可能使所有元素相等。

加入题单

算法标签: