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数列只有两项相等,也正好缺了一项,那就把两种 ...
随机推荐
- Android Study Notes
@1:按下back键退回到home界面时,会调用onDestroy() 按下back键时会调用onDestroy()销毁当前的activity,重新启动此activity时会调用onCreate()重 ...
- jmeter 请求发送加密参数(加密接口测试一)
最近在做http加密接口,请求头的uid参数及body的请求json参数都经过加密再发送请求,加密方式为:ase256.所以,jmeter发送请求前也需要对uid及json参数进行加密.我这里是让开发 ...
- CCF 权限查询(模拟)
试题编号: 201612-3 试题名称: 权限查询 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 授权 (authorization) 是各类业务系统不可缺少的组成部分,系统 ...
- OpenStack学习(二)
虚机安装成功后,,学习虚机的管理 虚机的管理主要使用以下命令 1. 虚机的管理 a. 创建 virt-install --name=wintest01 --ram 512 --vcpus=2 --di ...
- iOS & Android APP crash保护机制
一.背景 还在码代码,码好再BB... 二.思路 三.解决方案 四.注意点 五.开源项目 github:https://github.com/qiyer/QYCrashProtector
- c++ 中 BOOL与bool TRUE与true FALSE与false 区别
转自:http://blog.chinaunix.net/uid-28458801-id-3941112.html FALSE/TRUE与false/true的区别 1.FALSE/TRUE与fa ...
- Python3.x:SQLAlchemy操作数据库
Python3.x:SQLAlchemy操作数据库 前言 SQLAlchemy是一个ORM框架(Object Rational Mapping,对象关系映射),它可以帮助我们更加优雅.更加高效的实现数 ...
- Cisco 路由交换 常用查询语句
基本信息查询语句 #查看全配置信息 #show running-configure #查看vlan信息 #show vlan brief #查看物理直连信息 #show cdp neighbors d ...
- saltstack1
saltstack三种运行模式: local本地.master/minion(类似于agent).salt ssh saltstack三大功能: 远程执行.配置管理.云管理 saltstack安装:1 ...
- # 20145103《Java程序设计》第6周学习总结
20145103<Java程序设计>第6周学习总结 教材学习内容总结 第十章 第十章输入和输出 10.1.1 ·若要将数据从来源中取出,可以使用输入串流:若要将数据写入目的地,可以使用输出 ...