首页 > 其他分享 >CF #724(div2)A. Omkar and Bad Story,贪心,构造序列

CF #724(div2)A. Omkar and Bad Story,贪心,构造序列

时间:2023-02-08 16:03:03浏览次数:41  
标签:10 Story 12 integers int CF Bad array nice


problem

A. Omkar and Bad Story
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Omkar has received a message from Anton saying “Your story for problem A is confusing. Just make a formal statement.” Because of this, Omkar gives you an array a=[a1,a2,…,an] of n distinct integers. An array b=[b1,b2,…,bk] is called nice if for any two distinct elements bi,bj of b, |bi−bj| appears in b at least once. In addition, all elements in b must be distinct. Can you add several (maybe, 0) integers to a to create a nice array b of size at most 300? If a is already nice, you don’t have to add any elements.

For example, array [3,6,9] is nice, as |6−3|=|9−6|=3, which appears in the array, and |9−3|=6, which appears in the array, while array [4,2,0,6,9] is not nice, as |9−4|=5 is not present in the array.

For integers x and y, |x−y|=x−y if x>y and |x−y|=y−x otherwise.

Input
Each test contains multiple test cases. The first line contains t (1≤t≤50), the number of test cases. Description of the test cases follows.

The first line of each test case contains a single integer n (2≤n≤100) — the length of the array a.

The second line of each test case contains n distinct integers a1,a2,⋯,an (−100≤ai≤100) — the elements of the array a.

Output
For each test case, output one line containing YES if Omkar can create a nice array b by adding elements to a and NO otherwise. The case of each letter does not matter, so yEs and nO will also be accepted.

If the first line is YES, output a second line containing a single integer k (n≤k≤300).

Then output one line containing k distinct integers b1,b2,⋯,bk (−109≤bi≤109), the elements of the nice array b. b1,b2,⋯,bk can be in any order. For each ai in a, ai must appear at least once in b.

It can be proved that if Omkar can create such an array b, then he can also do so in a way that satisfies the above constraints.

If multiple solutions exist, you can print any.

Example
inputCopy
4
3
3 0 9
2
3 4
5
-7 3 13 -2 8
4
4 8 12 6
outputCopy
yes
4
6 0 3 9
yEs
5
5 3 1 2 4
NO
Yes
6
8 12 6 2 4 10
Note
For the first case, you can add integers to a to receive the array b=[6,0,3,9]. Note that |6−3|=|9−6|=|3−0|=3 and 3 is in b, |6−0|=|9−3|=6 and 6 is in b, and |9−0|=9 is in b, so b is nice.

For the second case, you can add integers to a to receive the array b=[5,3,1,2,4]. We have that |2−1|=|3−2|=|4−3|=|5−4|=1 is in b, |3−1|=|4−2|=|5−3|=2 is in b, |4−1|=|5−2|=3 is in b, and |5−1|=4 is in b, so b is nice.

For the fourth case, you can add integers to a to receive the array b=[8,12,6,2,4,10]. We have that |4−2|=|6−4|=|8−6|=|10−8|=|12−10|=2 is in b, |6−2|=|8−4|=|10−6|=|12−8|=4 is in b, |8−2|=|10−4|=|12−6|=6 is in b, |10−2|=|12−4|=8 is in b, and |12−2|=10 is in b, so b is nice.

It can be proven that for all other test cases it is impossible to create a nice array b.

solution

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int a[110];
int main(){
int T; cin>>T;
while(T--){
int n; cin>>n;
int mi = 1e9+10, mx = 0, ok = 1;
for(int i = 1; i <= n; i++){
int x; cin>>x;
mi = min(mi, x);
mx = max(mx, x);
if(x<0){
ok = 0;
}
}
if(ok==0){
cout<<"NO\n";
continue;
}
cout<<"YES\n";
cout<<mx+1<<"\n";
for(int i = 0; i <= mx; i++){
cout<<i<<" ";
}
cout<<"\n";
}
return 0;
}


标签:10,Story,12,integers,int,CF,Bad,array,nice
From: https://blog.51cto.com/gwj1314/6044580

相关文章

  • CF #727(div2)B. Love Song,前缀和
    problemB.LoveSongtimelimitpertest2secondsmemorylimitpertest256megabytesinputstandardinputoutputstandardoutputPetyaoncewroteasadlovesonga......
  • CF #727(div2)D. PriceFixed, 贪心,双指针
    problemD.PriceFixedtimelimitpertest1secondmemorylimitpertest256megabytesinputstandardinputoutputstandardoutputLenaisthemosteconomicalgirli......
  • CF #727(div2)C. Stable Groups,贪心,排序
    problemC.StableGroupstimelimitpertest1secondmemorylimitpertest256megabytesinputstandardinputoutputstandardoutputTherearenstudentsnumerated......
  • CF1693 ABCD 题解
    题目链接:https://codeforces.com/contest/1693这场的题都非常好啊……因为现在是从div1开始做了,所以可能刚开始会有点吃力(这场我就会做一个1B呜呜呜)1A先把后缀的极......
  • 每日一道思维题——CF1761C - Set Construction
    题意:存在一个n×n的01矩阵(i,j)处值为1代表Ai 是Aj的真子集,求出这个集合A思路:我们在一开始的时候将每个位置赋初值,若i处的值是j的真子集将i处的值赋值给j代码:#inc......
  • CF1511G Chips on a Board
    CF1511GChipsonaBoard比较有启发性的一道题。询问是最简单的nim游戏,不难发现若一列上有两个棋子,那么这两个棋子对于答案是没有贡献的,因此可以令\(c_i\)表示第\(......
  • CF961E 另解
    一种不用思考怎么树状数组/主席树的笨蛋做法将题目的a[i]视作一个横坐标[i-1,i],纵坐标[0,a[i]]的矩形,我们要统计的是二维平面上同时存在的(x,y)与(y,x)对数。这样的对子......
  • CF14D题解
    CF14DTwoPaths题解题目链接传送门题意简述给定一棵树,找出两条不经过相同点的最长路径,使得他们的长度乘积最大。题目分析首先,如果在一棵树上,两条路径没有共同的点,那......
  • CF1785B Letter Exchange 题解(思维+模拟)
    题目链接难度:绿+。题意给定\(t\)组testcase,每组testcase如下。有\(m\)个长度为3的字符串,每个字符都是\(\text{w}\)、\(\text{i}\)、\(\text{n}\)中的一个,一......
  • [CF1190D] Tokitsukaze and Strange Rectangle
    题目描述Thereare$n$pointsontheplane,the$i$-thofwhichisat$(x_i,y_i)$.Tokitsukazewantstodrawastrangerectangularareaandpickallt......