当前位置: 首页> 汽车> 车展 > 二手房_动漫双人互动模板_如何自己制作网站_技能培训班

二手房_动漫双人互动模板_如何自己制作网站_技能培训班

时间:2025/8/23 19:47:58来源:https://blog.csdn.net/jj12345jj198999/article/details/146053974 浏览次数: 0次
二手房_动漫双人互动模板_如何自己制作网站_技能培训班

time limit per test

2 seconds

memory limit per test

256 megabytes

A progressive square of size nn is an n×nn×n matrix. Maxim chooses three integers a1,1a1,1, cc, and dd and constructs a progressive square according to the following rules:

ai+1,j=ai,j+cai+1,j=ai,j+c

ai,j+1=ai,j+dai,j+1=ai,j+d

For example, if n=3n=3, a1,1=1a1,1=1, c=2c=2, and d=3d=3, then the progressive square looks as follows:

⎛⎝⎜1354687911⎞⎠⎟(1473695811)

Last month Maxim constructed a progressive square and remembered the values of nn, cc, and dd. Recently, he found an array bb of n2n2 integers in random order and wants to make sure that these elements are the elements of that specific square.

It can be shown that for any values of nn, a1,1a1,1, cc, and dd, there exists exactly one progressive square that satisfies all the rules.

Input

The first line contains an integer tt (1≤t≤1041≤t≤104) — the number of test cases.

The first line of each test case contains three integers nn, cc, and dd (2≤n≤5002≤n≤500, 1≤c,d≤1061≤c,d≤106) — the size of the square and the values of cc and dd as described in the statement.

The second line of each test case contains n⋅nn⋅n integers b1,b2,…,bn⋅nb1,b2,…,bn⋅n (1≤bi≤1091≤bi≤109) — the elements found by Maxim.

It is guaranteed that the sum of n2n2 over all test cases does not exceed 25⋅10425⋅104.

Output

For each test case, output "YES" in a separate line if a progressive square for the given nn, cc, and dd can be constructed from the array elements aa, otherwise output "NO".

You can output each letter in any case (lowercase or uppercase). For example, the strings "yEs", "yes", "Yes", and "YES" will be accepted as a positive answer.

Example

Input

Copy

 

5

3 2 3

3 9 6 5 7 1 10 4 8

3 2 3

3 9 6 5 7 1 11 4 8

2 100 100

400 300 400 500

3 2 3

3 9 6 6 5 1 11 4 8

4 4 4

15 27 7 19 23 23 11 15 7 3 19 23 11 15 11 15

Output

Copy

NO
YES
YES
NO
NO

解题说明:此题是一道数学题,从题目意思中的得知,这种方阵仅由n,c,d以及a[0][0]决定,所以它唯一可能对应的方阵我们可以找到,然后就是比较两个方阵里的数能不能对应即可。这里可以采用集合来做,排序后逐一比较。

#include <bits/stdc++.h>
using namespace std;int solve(int n, int c, int d, vector<int> a)
{sort(a.begin(), a.end());vector<int> q;for (long long i = 0; i < n; i++){for (long long j = 0; j < n; j++) {q.push_back(a[0] + c * i + d * j);}}sort(q.begin(), q.end());for (long long i = 0; i < n * n; i++){if (a[i] != q[i]){return false;}}return true;
}int main() 
{int t;cin >> t;while (t--) {int n, c, d;cin >> n >> c >> d;vector<int> a(n * n);for (long long i = 0; i < n * n; i++){cin >> a[i];}if (solve(n, c, d, a)){cout << "YES" << endl;}else{cout << "NO" << endl;}}return 0;
}

关键字:二手房_动漫双人互动模板_如何自己制作网站_技能培训班

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: