Codeforces 297C. Splitting the Uniqueness
Polar bears like unique arrays — that is, arrays without repeated elements.
You have got a unique array s with length n containing non-negative integers. Since you are good friends with Alice and Bob, you decide to split the array in two. Precisely, you need to construct two arrays a and b that are also of length n, with the following conditions for all i(1 ≤ i ≤ n):
- ai, bi are non-negative integers;
- si = ai + bi .
Ideally, a and b should also be unique arrays. However, life in the Arctic is hard and this is not always possible. Fortunately, Alice and Bob are still happy if their arrays are almost unique. We define an array of length n to be almost unique, if and only if it can be turned into a unique array by removing no more than  entries.
 entries.
For example, the array [1, 2, 1, 3, 2] is almost unique because after removing the first two entries, it becomes [1, 3, 2]. The array [1, 2, 1, 3, 1, 2] is not almost unique because we need to remove at least 3 entries to turn it into a unique array.
So, your task is to split the given unique array s into two almost unique arrays a and b.
The first line of the input contains integer n (1 ≤ n ≤ 105).
The second line contains n distinct integers s1, s2, ... sn (0 ≤ si ≤ 109).
If it is possible to make Alice and Bob happy (if you can split the given array), print "YES" (without quotes) in the first line. In the second line, print the array a. In the third line, print the array b. There may be more than one solution. Any of them will be accepted.
If it is impossible to split s into almost unique arrays a and b, print "NO" (without quotes) in the first line.
6
12 5 8 3 11 9
YES
6 2 6 0 2 4
6 3 2 3 9 5
In the sample, we can remove the first two entries from a and the second entry from b to make them both unique.
分析:
因为一个序列如果是近似不同的的序列,那么它有至少 ⌊ 2n / 3⌋的元素是不同的...所以我们把s序列分成三个部分,第一个部分保证a互不相同,第二个部分保证b互不相同,第三个部分保证ab都互不相同...如下图:

设x=n/3(上取整)
i∈[1,x] a=i-1
i∈[x+1,n-x] b=i-1
i∈[n-x+1,n] b=n-i+1
代码:
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
//by NeighThorn
using namespace std;
//眉眼如初,岁月如故 const int maxn=100000+5; int n,x; struct M{
int a,b,s,id;
friend bool operator < (M a,M b){
return a.s<b.s;
}
}sxy[maxn]; inline bool cmp(M a,M b){
return a.id<b.id;
} signed main(void){
scanf("%d",&n);x=(n+2)/3;
for(int i=1;i<=n;i++)
scanf("%d",&sxy[i].s),sxy[i].id=i;
sort(sxy+1,sxy+n+1);
for(int i=1;i<=x;i++)
sxy[i].a=i-1,sxy[i].b=sxy[i].s-i+1;
for(int i=x+1;i<=n-x;i++)
sxy[i].b=i-1,sxy[i].a=sxy[i].s-i+1;
for(int i=n-x+1;i<=n;i++)
sxy[i].b=n-i,sxy[i].a=sxy[i].s-sxy[i].b;
sort(sxy+1,sxy+n+1,cmp);puts("YES");
for(int i=1;i<=n;i++)
printf("%d ",sxy[i].a);
puts("");
for(int i=1;i<=n;i++)
printf("%d ",sxy[i].b);
puts("");
return 0;
}//Cap ou pas cap. Pas cap.
By NeighThorn
Codeforces 297C. Splitting the Uniqueness的更多相关文章
- CodeForces 297C Splitting the Uniqueness (脑补构造题)
		题意 Split a unique array into two almost unique arrays. unique arrays指数组各个数均不相同,almost unique arrays指 ... 
- Codeforces.297C.Splitting the Uniqueness(构造)
		题目链接 \(Description\) 给定一个长为n的序列A,求两个长为n的序列B,C,对任意的i满足B[i]+C[i]=A[i],且B,C序列分别至少有\(\lfloor\frac{2*n}{3 ... 
- 【CodeForces 297C】Splitting the Uniqueness
		题意 序列s有n个数,每个数都是不同的,把它每个数分成两个数,组成两个序列a和b,使ab序列各自去掉个数后各自的其它数字都不同. 如果存在一个划分,就输出YES,并且输出两个序列,否则输出NO. 分析 ... 
- Codeforces Round #180 (Div. 1 + Div. 2)
		A. Snow Footprints 如果只有L或者只有R,那么起点和终点都在边界上,否则在两者的边界. B. Sail 每次根据移动后的曼哈顿距离来判断是否移动. C. Parity Game 如果 ... 
- Educational Codeforces Round 4 A. The Text Splitting 水题
		A. The Text Splitting 题目连接: http://www.codeforces.com/contest/612/problem/A Description You are give ... 
- Codeforces 754A Lesha and array splitting(简单贪心)
		A. Lesha and array splitting time limit per test:2 seconds memory limit per test:256 megabytes input ... 
- Codeforces Round #452 (Div. 2)-899A.Splitting in Teams   899B.Months and Years   899C.Dividing the numbers(规律题)
		A. Splitting in Teams time limit per test 1 second memory limit per test 256 megabytes input standar ... 
- Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2) C. Maximum splitting
		地址: 题目: C. Maximum splitting time limit per test 2 seconds memory limit per test 256 megabytes input ... 
- Codeforces Round #390 (Div. 2) A. Lesha and array splitting
		http://codeforces.com/contest/754/problem/A 题意: 给出一串序列,现在要把这串序列分成多个序列,使得每一个序列的sum都不为0. 思路: 先统计一下不为0的 ... 
随机推荐
- STMS传输队列中的请求状态一直是Running不能结束
			通过STMS传输请求时,遇到了如下问题: STMS传输请求,不论等多久的时间,请求状态一直是running,不能结束.但检查传输的内容时,发现CHANGE REQUEST包含的内容已经传输到目标Cli ... 
- HTTP-点开浏览器输入网址背后发生的那点事
			前言 Internet最早来源于美国国防部ARPANet,1969年投入运行,到现在已有很长一段路了,各位想要了解发展史可以百度下,这里就不多说了. 现如今当我们想要获取一些资料,首先是打开某个浏览器 ... 
- PHP之基本目录操作
			一.创建目录 mkdir ($pathname, $mode = 0777, $recursive = false, $context = null) $pathname: 目录路径 $mode : ... 
- 想成长为一名年薪50万+的实战型架构师?必掌握这7大实战技能经验--阿里mike
			想成为一名架构师,但是架构师对应的技能,我应该掌握哪些啊?以及掌握的程度是什么样的?如何成为一名真正的实战性架构师? 我简要分为以下7点来谈谈,从技能的角度抛砖引玉,希望你对你架构师之路有一定的参考. ... 
- 精通SpringBoot--整合Redis实现缓存
			今天我们来讲讲怎么在spring boot 中整合redis 实现对数据库查询结果的缓存.首先第一步要做的就是在pom.xml文件添加spring-boot-starter-data-redis.要整 ... 
- python学习——StringIO和BytesIO
			StringIO 很多时候,数据读写不一定是文件,也可以在内存中读写. StringIO顾名思义就是在内存中读写str. 要把str写入StringIO,我们需要先创建一个StringIO,然后,像文 ... 
- 100个经典C语言程序(益智类)
			100个经典C语言程序(益智类) [1.绘制余弦曲线] 在屏幕上用“*”显示0~360度的余弦函数cos(x)曲线 [问题分析与算法设计] 利用cos(x)的左右对称性,将屏幕的行方向定义为x,列方向 ... 
- Java的内存回收
			一.java引用的种类 1.对象在内存中的状态 可达状态:当一个对象被创建后,有一个以上的引用变量指向它. 可恢复状态: 不可达状态:当对象的所有关联被切断,且系统调用所有对象的finalize方法依 ... 
- TCP/IP网络编程之基于UDP的服务端/客户端
			理解UDP 在之前学习TCP的过程中,我们还了解了TCP/IP协议栈.在四层TCP/IP模型中,传输层分为TCP和UDP这两种.数据交换过程可以分为通过TCP套接字完成的TCP方式和通过UDP套接字完 ... 
- Django之session验证的三种姿势
			一.什么是session session是保存在服务端的键值对,Django默认支持Session,并且默认是将Session数据存储在数据库中,即:django_session 表中. 二.FVB中 ... 
