CodeForces 297C Splitting the Uniqueness (脑补构造题)
题意
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 - i. a 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 (脑补构造题)的更多相关文章
- Codeforces 297C. Splitting the Uniqueness
C. Splitting the Uniqueness time limit per test:1 second memory limit per test:256 megabytes input:s ...
- 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 297D Color the Carpet (脑补题)
题意 一个h*w的矩阵上面涂k种颜色,并且每行相邻格子.每列相邻格子都有=或者!=的约束.要求构造一种涂色方案使得至少有3/4的条件满足. 思路 脑补神题--自己肯定想不出来T_T-- 官方题解: 2 ...
- Educational Codeforces Round 7 D. Optimal Number Permutation 构造题
D. Optimal Number Permutation 题目连接: http://www.codeforces.com/contest/622/problem/D Description You ...
- Codeforces Gym 100342H Problem H. Hard Test 构造题,卡迪杰斯特拉
Problem H. Hard TestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/at ...
- Codeforces Round #339 (Div. 1) C. Necklace 构造题
C. Necklace 题目连接: http://www.codeforces.com/contest/613/problem/C Description Ivan wants to make a n ...
- struts2+hibernate+spring注解版框架搭建以及简单测试(方便脑补)
为了之后学习的日子里加深对框架的理解和使用,这里将搭建步奏简单写一下,目的主要是方便以后自己回来脑补: 1:File--->New--->Other--->Maven--->M ...
- struts2+hibernate+spring配置版框架搭建以及简单测试(方便脑补)
为了之后学习的日子里加深对框架的理解和使用,这里将搭建步奏简单写一下,目的主要是方便以后自己回来脑补: 1:File--->New--->Other--->Maven--->M ...
- Codeforces - 814B - An express train to reveries - 构造
http://codeforces.com/problemset/problem/814/B 构造题烦死人,一开始我还记录一大堆信息来构造p数列,其实因为s数列只有两项相等,也正好缺了一项,那就把两种 ...
随机推荐
- Python(面向对象5——高级)
面向对象进阶 一 isinstance(obj,cls)和issubclass(sub,super) isinstance(obj,cls)检查是否obj是否是类 cls 的对象 1 class Fo ...
- Outputting Strings in the Console
Outputting Strings in the Console #include <windows.h> class Console {public: enum fore_color ...
- Jquery each循环用法小结
var str = res.ZhaoPian; var piclist = str.substring(0, str.length - 1).split(','); $.each(piclist, f ...
- 101. Symmetric Tree(判断二叉树是否对称)
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For ...
- 如何使用iClap进行产品管理?
iClap概述: iClap是DevStore的全新产品,于2015年8月29号上线,该款产品专注于为移动互联网企业提供企业规范化解决方案,颠覆传统的产品管理模式,实现产品管理场景化.APP.甚至原型 ...
- C++之旅(第一天)
基础知识 完全支持C语言 可以在C++引入C的头文件 #include <stdio.h> #include <iostream> int main() { } 输入和输出 C ...
- js经典面试问题:如何让for循环中的setTimeout()函数像预想中一样工作?
setTimeout()是js中的一类重要函数,将一段代码延迟一定时间并异步执行.但是这个函数经常不听话.在实践中,可能经常有人碰到类似下面的这种情况: for (var i = 1; i <= ...
- 【Python】IO编程
文件读写 StringIO和BytesIO 操作文件和目录 序列化 学习廖老师的py官网的笔记 1.stream的概念.数据交换通常需要建立两根“水管”. 2.同步IO和异步IO.异步性能高,但是编程 ...
- jQuery与直接写JS的区别详细解析
jQuery代码具体的写法和原生的Javascript写法在执行常见操作时的区别如下所示.需要的朋友可以过来参考下 要使用jQuery,首先要在HTML代码最前面加上对jQuery库的引用,比 ...
- java压缩多个文件
首先创建一个工具类,定义好接口,这里的参数1:fileList:多个文件的path+name2: zipFileName:压缩后的文件名 下面是代码,注释已经很详细了 public class ZIP ...