题意

Split a unique array into two almost unique arrays.

unique arrays指数组各个数均不相同,almost unique arrays指可以删掉数后再判断。

思路

略神的数学构造题。。。

官方题解:

An equivalent definition for almost unique, is arrays with at least ⌊ 2n / 3⌋ different elements. The idea is to split s into three parts. In the first part, we give uniqueness to a. In the second part, we give uniqueness to b. In the third part, we give uniqueness to both.

Lets assume s is sorted. Since s is an unique array, si ≥ i for all i (0-based). The image below will give some intuition on how to split it. ais red, b is blue, the length of the bar represent the magnitude of the number. In the first and second part, we do not care about the array that we are not giving uniqueness to.

We will make an example with n = 30.

i = 0... 9:  assign ai = i (do not care values of b)

i = 10... 19:  assign bi = i (do not care values of a)

i = 20... 29:  assign bi = 29 - ia takes the remains. From i = 20, a will have strictly increasing values starting from at least 11.

代码

[cpp]
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#define MID(x,y) ((x+y)/2)
#define MEM(a,b) memset(a,b,sizeof(a))
#define REP(i, begin, end) for (int i = begin; i <= end; i ++)
using namespace std;

typedef long long LL;

struct num{
int value;
int id;
num(){}
num(int _id, int _value){id = _id; value = _value;}
};
bool cmp(num n1, num n2){
return n1.value < n2.value;
}
typedef vector <num> VI;

VI v;
int a[100005], b[100005];
int main(){
//freopen("test.in", "r", stdin);
//freopen("test.out", "w", stdout);
int n;
scanf("%d", &n);
REP(i, 0, n-1){
int tmp;
scanf("%d", &tmp);
v.push_back(num(i, tmp));
}
sort(v.begin(), v.end(), cmp);
int d = (int)ceil((double)n/3);
for (int i = 0; i < min(n, d); i ++){
a[v[i].id] = i;
b[v[i].id] = v[i].value - a[v[i].id];
}
for (int i = d; i < min(n, d*2); i ++){
b[v[i].id] = i;
a[v[i].id] = v[i].value - b[v[i].id];
}
for (int i = 2*d; i < n; i ++){
b[v[i].id] = n - 1 - i;
a[v[i].id] = v[i].value - b[v[i].id];
}
puts("YES");
for (int i = 0; i < n-1; i ++) printf("%d ", a[i]); printf("%d\n", a[n-1]);
for (int i = 0; i < n-1; i ++) printf("%d ", b[i]); printf("%d\n", b[n-1]);
return 0;
}
[/cpp]

CodeForces 297C Splitting the Uniqueness (脑补构造题)的更多相关文章

  1. Codeforces 297C. Splitting the Uniqueness

    C. Splitting the Uniqueness time limit per test:1 second memory limit per test:256 megabytes input:s ...

  2. 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 ...

  3. CodeForces 297D Color the Carpet (脑补题)

    题意 一个h*w的矩阵上面涂k种颜色,并且每行相邻格子.每列相邻格子都有=或者!=的约束.要求构造一种涂色方案使得至少有3/4的条件满足. 思路 脑补神题--自己肯定想不出来T_T-- 官方题解: 2 ...

  4. Educational Codeforces Round 7 D. Optimal Number Permutation 构造题

    D. Optimal Number Permutation 题目连接: http://www.codeforces.com/contest/622/problem/D Description You ...

  5. Codeforces Gym 100342H Problem H. Hard Test 构造题,卡迪杰斯特拉

    Problem H. Hard TestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/at ...

  6. Codeforces Round #339 (Div. 1) C. Necklace 构造题

    C. Necklace 题目连接: http://www.codeforces.com/contest/613/problem/C Description Ivan wants to make a n ...

  7. struts2+hibernate+spring注解版框架搭建以及简单测试(方便脑补)

    为了之后学习的日子里加深对框架的理解和使用,这里将搭建步奏简单写一下,目的主要是方便以后自己回来脑补: 1:File--->New--->Other--->Maven--->M ...

  8. struts2+hibernate+spring配置版框架搭建以及简单测试(方便脑补)

    为了之后学习的日子里加深对框架的理解和使用,这里将搭建步奏简单写一下,目的主要是方便以后自己回来脑补: 1:File--->New--->Other--->Maven--->M ...

  9. Codeforces - 814B - An express train to reveries - 构造

    http://codeforces.com/problemset/problem/814/B 构造题烦死人,一开始我还记录一大堆信息来构造p数列,其实因为s数列只有两项相等,也正好缺了一项,那就把两种 ...

随机推荐

  1. SQL Server 创建游标(cursor)

    游标的定义: 游标则是处理结果集的一种机制,它可以定位到结果集中的某一行,也可以移动游标定位到你所需要的行中进行操作数据.与 select 语句的不同是,select 语句面向的是结果集,游标面向的是 ...

  2. Maven详解(转)

    原文出自: http://www.cnblogs.com/hongwz/p/5456578.html http://ifeve.com/maven-1/ Maven介绍: Maven是一个强大的Jav ...

  3. 前端虚拟接口mockjs的使用

    最近在学习VueJS,也进一步学习了ES6,看了一遍之后,难免手痒,所以想仿写点什么,但是数据是个问题,你总不能写个分页,写个轮播吧,但是在公司做自己的东西找后台要接口也不那么像回事,怎么办呢? 无意 ...

  4. Linux 实时性能测试工具——Cyclictest

    Cyclictest 是 rt-tests 下的一个测试工具,也是rt-tests 下使用最广泛的测试工具,一般主要用来测试使用内核的延迟,从而判断内核的实时性. 1.2 cyclictest 安装 ...

  5. c++ 中 BOOL与bool TRUE与true FALSE与false 区别

    转自:http://blog.chinaunix.net/uid-28458801-id-3941112.html   FALSE/TRUE与false/true的区别 1.FALSE/TRUE与fa ...

  6. iis日志时间与本地日期不一样

    iis日志里面的时间是 UTC时间,所以要自已加时区进行转换:即 utc时间+8小时:

  7. 20145324 Java实验一

    北京电子科技学院(BESTI) 实 验 报 告 课程:JAVA 班级:1453 姓名:王嘉澜 学号:20145324 成绩: 指导教师:娄嘉鹏 实验日期:2016.4.8 实验密级: 预习程度: 实验 ...

  8. [转]C语言 gets()和scanf()函数的区别

    scanf( )函数和gets( )函数都可用于输入字符串,但在功能上有区别.若想从键盘上输入字符串"hi hello",则应该使用__gets__函数. gets可以接收空格:而 ...

  9. Java中private、protected、public和default的区别-001

    public: 具有最大的访问权限,可以访问任何一个在classpath下的类.接口.异常等.它往往用于对外的情况,也就是对象或类对外的一种接口的形式. protected: 主要的作用就是用来保护子 ...

  10. Oracle查询一个表的数据插入到另一个表

    1. 新增一个表,通过另一个表的结构和数据 create table XTHAME.tab1 as select * from DSKNOW.COMBDVERSION 2. 如果表存在: insert ...