博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CF&&CC百套计划2 CodeChef December Challenge 2017 Chef and Hamming Distance of arrays
阅读量:6221 次
发布时间:2019-06-21

本文共 2697 字,大约阅读时间需要 8 分钟。

 

#include
#include
#include
using namespace std; #define N 100001 int a[N],b[N];int sum[N],wh[N][2]; int num1[N],num2[N]; void read(int &x){ x=0; char c=getchar(); while(!isdigit(c)) c=getchar(); while(isdigit(c)) { x=x*10+c-'0'; c=getchar(); }} int main(){ int T; read(T); int n; int tot1,tot2; while(T--) { memset(sum,0,sizeof(sum)); memset(wh,0,sizeof(wh)); read(n); for(int i=1;i<=n;++i) { read(a[i]); sum[a[i]]++; if(wh[a[i]][0]) wh[a[i]][1]=i; else wh[a[i]][0]=i; } tot1=tot2=0; for(int i=1;i

 

Read problems statements in 

.

Chef likes to work with arrays a lot. Today he has an array A of length N consisting of positive integers. Chef's little brother likes to follow his elder brother, so he thought of creating an array B of length N. The little brother is too small to think of new numbers himself, so he decided to use all the elements of array A to create the array B. In other words, array B is obtained by shuffling the elements of array A.

The little brother doesn't want Chef to know that he has copied the elements of his array A. Therefore, he wants to create the array B in such a way that the Hamming distance between the two arrays A and B is maximized. The Hamming distance betweenA and B is the number of indices i (1 ≤ i ≤ N) such that Ai ≠ Bi.

The brother needs your help in finding any such array B. Can you please find one such array for him?

Note that it's guaranteed that no element in A appears more than twice, i.e. frequency of each element is at most 2.

Input

 

  • The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
  • The first line of each test case contains an integer N denoting the length of the array A.
  • The second line contains N space-separated integers A1, A2 ... AN.

 

Output

 

  • For each test case, print two lines.
  • The first line should contain the maximum possible Hamming distance that array Bcan have from array A.
  • The second line should contain N space-separated integers denoting the array B; the i-th integer should denote the value of Bi. Note that B should be an array obtained after shuffling the elements of A.

 

Constraints

  • 1 ≤ T ≤ 10
  • 1 ≤ N ≤ 105
  • 1 ≤ Ai ≤ 105
  • The frequency of each integer in the array A will be at most 2.

Subtasks

Subtask #1 (30 points): all elements in the array A are unique

Subtask #2 (30 points): 5 ≤ N ≤ 105

Subtask #3 (40 points): original constraints

Example

Input321 231 2 142 6 5 2Output22 122 1 146 2 2 5

转载于:https://www.cnblogs.com/TheRoadToTheGold/p/8059993.html

你可能感兴趣的文章
siebel CRM初学
查看>>
JS组件系列——Bootstrap寒冬暖身篇:弹出框和提示框效果以及代码展示
查看>>
linux命令之iotop
查看>>
老板必备:核心员工跳槽时,必聊的8个话题(转)
查看>>
C++ 中vector的使用方法
查看>>
基于mysqldump搭建gtid主从
查看>>
Apache Flink fault tolerance源码剖析(五)
查看>>
HTAP数据库 PostgreSQL 场景与性能测试之 18 - (OLAP) 用户画像圈人场景 - 数组包含查询与聚合...
查看>>
GitHub最新命令使用教程
查看>>
web中间件切换(was切tomcat)
查看>>
onvif规范的实现:server端Discovery实现,通过OnvifTestTool12.06测试
查看>>
Hadoop: MapReduce2多个job串行处理
查看>>
2017阿里双11交易创建峰值 32.5 万笔/秒!
查看>>
【译】统一样式语言
查看>>
十分钟教程:用Keras实现seq2seq学习
查看>>
Netflix: 使用 React 构建高性能的电视用户界面
查看>>
在网站 Logo 上右击时提示下载网站的 Logo 素材下载
查看>>
移动端设计最佳实践
查看>>
运营商如何从NaaS中获益
查看>>
大数据计数原理1+0=1这你都不会算(一)
查看>>