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数列只有两项相等,也正好缺了一项,那就把两种 ...
随机推荐
- testng生成报告 testng-xslt 美化测试报告
testng生成报告 testng-xslt 美化测试报告 testng生成报告 testng-xslt 美化测试报告 用TestNG测试后,自动会生成html的测试报告.利用 testNG-xslt ...
- Django中contenttype的应用
content_type表将app名称与其中的表的关系进行保存 通过下边的示例来理解content_type的具体应用: models: from django.db import models fr ...
- 字典的fromkeys的用法
fromkeys方法语法 dict.fromkeys(iterable[,value=None]) iterable 用于创建新的字典的键的可迭代对象(字符串,列表,元组,字典) value 可选参数 ...
- SQL Server outer apply 和 cross apply
先说点题外话,因为后面我会用到这个函数. 前两天自定义了一个 sql 的字符串分割函数(Split),不过后来发现有点问题,例如: select * from Split(default,'123,4 ...
- Mybatis入门配置
MyBatis 本是apache的一个开源项目iBatis, 2010年这个项目由apache software foundation 迁移到了google code,并且改名为MyBatis .20 ...
- 跨域问题-jsonp
前端同源策略并不会拦截静态资源请求,那么就将接口伪装成资源,然后后端配合返回一个前端预定义的方法调用,将返回值放入调用该函数的形参即可 <!DOCTYPE html> <html l ...
- 基于EasyUI 快速搭建权限管理平台
前言: 一.用户角色权限设计思路: <1>不同职责的人员,对于系统操作的权限应该是不同;<2>可以对“组”进行权限分配;<3>权限管理系统应该是可扩展的;<4 ...
- curl 命令返回json结构human readable
在curl命令后面添加 | python -m json.tool 不想显示curl的统计信息,添加 -s参数 例: curl https://news-at.zhihu.com/api/4/news ...
- c++之旅:多态
多态 同一消息根据发送对象的不同而产生不同的行为,多态是建立的在封装和继承的基础之上 一个小案例引发的问题 #include <iostream> using namespace std; ...
- Core ML 入门
1.下载Xcode 9 2.下载模型,https://developer.apple.com/machine-learning/ 3.开动.. 4.待续 模拟器66的