题意

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. Java基础知识陷阱(七)

    本文发表于本人博客. 上次说了下HashSet和HashMap之间的关系,其中HashMap这个内部有这么一句: static final float DEFAULT_LOAD_FACTOR = 0. ...

  2. hbase(一)

    1.hbase安装参考 http://blog.csdn.net/wild46cat/article/details/53214159 2.遇到的问题: ERROR: The node /hbase ...

  3. Codeforces Round #416 (Div. 2) D. Vladik and Favorite Game

    地址:http://codeforces.com/contest/811/problem/D 题目: D. Vladik and Favorite Game time limit per test 2 ...

  4. python替换一个文件里面的特定内容

    f = open("1.txt", "r", encoding="utf-8") f_new = open("2.txt" ...

  5. ABP官方文档翻译 2.4 日志

    日志 服务端 获取记录器 基类日志记录器 配置 Abp.Castle.Log4Net包 客户端 服务端 ABP使用Castle Windsor`s 日志设备.它可以使用不同的日志类库:Log4Net, ...

  6. 在VS2015中用C++编写可被其它语言调用的动态库DLL

    转自:http://blog.csdn.net/songyi160/article/details/50754705 VS2015用C++创建动态库DLL步骤如下: (1)启动VS2015>文件 ...

  7. 架构私用Nuget服务器

    1.新建一个空的asp.net站点 2.通过nuget引用 Nuget.Server程序集,引用后项目会多出一些文件.修改web.config 里的apikey为你要上传包时用的apikey,我的为: ...

  8. 20145324 《Java程序设计》第5周学习总结

    20145324 <Java程序设计>第5周学习总结 教材学习内容总结 第八章 1.java中所有错误都会被包装成为对象 2.可以使用尝试(try)执行程序并捕捉代表错误的对象后做一些处理 ...

  9. XML常用标签的介绍

    1.引言 在使用Java时经常遇到使用XML的情况,而因为对XML不太了解,经常配置时粘贴复制,现在对它进行总结,以备以后使用. 2.XML常见的定义 (1)XML(Extensible Markup ...

  10. Swift学习笔记 - OC中关于NSClassFromString获取不到Swift类的解决方案

    在OC和Swift混编的过程中发现在OC中通过NSClassFromString获取不到Swift中的类,调研了一下发现问题所在,下面是我的解决方案: 问题的发现过程 UIViewController ...