codeforces 856A (思维)
来源:互联网 发布:怎么样配衣服 知乎 编辑:程序博客网 时间:2024/06/05 12:49
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 containing n 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
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).
Output
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.
Example
Input
3
3
1 10 100
1
1
2
2 4
Output
YES
1 2 3
YES
1
YES
1 2
给你一个集合A,让你构造一个集合B,使得A中任何一个元素+B中任何一个元素的所有能产生的和都不相同。转化一下 ai+bj!=ak+bm; ai-ak!=bj-bm;
找出所有的差值存下,然后扫一遍所有的数,如果能成立就放进去,一开始 b[0]=1;
#include <bits/stdc++.h>using namespace std;int vis[1000010];int b[330];int a[330];const int BUF=30000000; char Buf[BUF],*buf=Buf; inline void read(int&a){for(a=0;*buf<48;buf++);while(*buf>47)a=a*10+*buf++-48;}int main(){ int t; fread(Buf,1,BUF,stdin);//重点 read(t); while(t--) { int n; read(n); memset(vis,0,sizeof(vis)); for(int i=1;i<=n;i++) read(a[i]); int cnt=1; b[0]=1; if(n==1) { puts("YES"); printf("%d\n",b[0] ); continue; } sort(a+1,a+n+1); for(int i=1;i<=n;i++) for(int j=i+1;j<=n;j++) vis[a[j]-a[i]]=1; for(int i=2;i<=1000000;i++) { int f=0; for(int j=0;j<cnt;j++) { if(vis[i-b[j]]) { f=1; break; } } if(!f) b[cnt++]=i; if(cnt>=n) break; } if(cnt>=n) { puts("YES"); for(int i=0;i<cnt;i++) printf("%d ",b[i] ); printf("\n"); } else puts("NO"); }}
- codeforces 856A (思维)
- CodeForces 348A Mafia (思维)
- codeforces 359A- Table(简单思维)
- Codeforces 134A-Average Numbers(思维)
- Codeforces 135A-Replacement(思维)
- CodeForces 598A Tricky Sum(思维)
- 【CodeForces】300A - Array(思维)
- 【CodeForces】699A - One Bomb(思维)
- 【CodeForces】348A - Mafia(二分 & 思维)
- Codeforces 348A:Mafia(二分+思维)
- 【CodeForces】701A - Cards(暴力 || 思维)
- 【Codeforces】-701A-Cards(思维)
- 【codeforces div2 A】Calculating Function(思维)
- 【Codeforces-402A】-Pupils Redistribution(思维)
- codeforces 154A (对 思维)
- codeforces 754A(思维题)
- 【codeforces】A. Array(思维水题)
- CodeForces 808A Lucky Year(思维)
- 购物车
- Netty集成Google的ProtoBuf序列化
- Delphi第三方控件dxdbgrid中option属性详解
- Java update dynamodb api demo with UpdateItemSpec
- 数据结构——双循环链表一部分功能的C语言实现
- codeforces 856A (思维)
- mysql批量插入优化
- 1 2汉字转拼音 3百度翻译
- 阿里云全民云计算活动:云服务器ECS二折起(云主机)采购指南
- 聚类算法
- 加入shiro后, 页面始终不没有样式
- Java多线程系列--“JUC集合”03之 CopyOnWriteArraySet
- java list 删除重复的,借助map
- 字符串匹配KMP算法