codeforces 856a
来源:互联网 发布:淘宝品牌升级 编辑:程序博客网 时间:2024/06/08 10:17
Masha and Grisha like studying sets of positive integers.
One day Grisha has written a set A containing n different integers ai on a blackboard. Now he asks Masha to create a set B containingn different integers bj such that all n2 integers that can be obtained by summing up ai and bj for all possible pairs of i and j are different.
Both Masha and Grisha don't like big numbers, so all numbers in A are from 1 to 106, and all numbers in B must also be in the same range.
Help Masha to create the set B that satisfies Grisha's requirement.
Input data contains multiple test cases. The first line contains an integer t — the number of test cases (1 ≤ t ≤ 100).
Each test case is described in the following way: the first line of the description contains one integer n — the number of elements in A(1 ≤ n ≤ 100).
The second line contains n integers ai — the elements of A (1 ≤ ai ≤ 106).
For each test first print the answer:
- NO, if Masha's task is impossible to solve, there is no way to create the required set B.
- YES, if there is the way to create the required set. In this case the second line must contain n different positive integers bj — elements of B (1 ≤ bj ≤ 106). If there are several possible sets, output any of them.
331 10 1001122 4
YES1 2 3 YES1 YES1 2
将所有a+b都不相等转换为|ai-aj|!=|bq-bp|,暴力。
#include<iostream>#include<stdio.h>#include<algorithm>#include<string.h>#include<queue>using namespace std;bool vis[1000005]; //表示这个差值有没有产生过 int a[105];int b[105];int n;int main(){int t;scanf("%d",&t);while(t--){memset(vis,0,sizeof(vis));scanf("%d",&n);for(int i=0;i<n;i++)scanf("%d",&a[i]);if(n==1){printf("YES\n");printf("1\n");continue;}sort(a,a+n);for(int i=0;i<n;i++) //存储数组a产生所有差值 for(int j=i+1;j<n;j++)vis[a[j]-a[i]]=1;b[0]=1;int cnt=1;for(int i=2;i<1000005;i++){bool flag=false;for(int j=0;j<cnt;j++) //只要bk与之前所有的数字产生的差值都没有被记录过这个bk就是可以的 {if(vis[i-b[j]]){flag=true;break;}}if(!flag){b[cnt++]=i;}if(cnt>=n)break;}if(cnt>=n){printf("YES\n");for(int i=0;i<n-1;i++)printf("%d ",b[i]);printf("%d\n",b[n-1]);}else{printf("NO\n");}}}
- Codeforces 856A
- codeforces 856a
- codeforces 856A (思维)
- CodeForces-a
- Codeforces 903A A
- CodeForces 18A A - Triangle
- CodeForces 133A A. HQ9+
- codeforces 651A A. Joysticks
- 【Codeforces 597A】A. Divisibility
- 【 Codeforces 615A】A. Bulbs
- A. Divisibility CodeForces 597A
- codeforces 417A A. Elimination
- CodeForces 534A A. Exam
- codeforces#98 a
- codeforces#99 a
- codeforces 105 div2 A
- codeforces #121 A
- Codeforces 185A Plant
- 2016奇虎360研发工程师内推笔试编程题
- matplotlib学习之绘图基础
- centos7 locate
- 推荐一个真正免费的计算机毕业设计网址
- 兼容性写法(部分)
- codeforces 856a
- Leetcode第二题,用链表实现两个非负整数求和
- 解决在firefox上安装附加组件无法使用的问题
- C++信息学奥赛一本通1000
- 清北学堂-D4-T1-beautiful
- 1093. Count PAT's (25)
- 【Android】の基础——ListView和RecyclerView缓存机制
- Jquery
- 了解线程安全性