序列s有n个数,每个数都是不同的,把它每个数分成两个数,组成两个序列a和b,使ab序列各自去掉个数后各自的其它数字都不同。

如果存在一个划分,就输出YES,并且输出两个序列,否则输出NO。

分析

两个月前做的一题,那时候问学长才会做的,现在刚看到题又懵逼了。再做过了一遍。

序列s的每个数都是不同的,我们先给s按递增排序,然后构造:k=

  个数 第二个个数  剩下≤个数
s s[i] s[i+k] s[i+2*k]
a s[i] 0  
b 0 s[i+k] 0 1 2 ...  ..2 1 0 即k-i

1≤i≤k

分配完前两段,问题变成除去k个0后,剩下的数都要不同。

因为i每增加1,s[i]至少增加1,所以 b的第k+1个数≥k,也就是是说b这个序列中间那一段数是≥k的,那后面≤k个数就可以放上0到k-1了。因为s[i]递增了,要让si-bi的数也不同,那bi要递减才能保证。那会不会和前面冲突呢?不会。因为a的第三段最小的是i=1时的s[i+2*k]-k+1,a第一段最大的是s[k],又因为si是互不相同的,所以有s[i+2*k]-s[k]≥k+1,所以s[i+2*k]-k+1-s[k]≥2,所以a第三段所有数都大于第一段任意数。

cf上题解的做法是

  个数 第二个个数  剩下≤个数
s s[i] s[i+k] s[i+2*k]
a 0 1 2... k-1    
b   k k+1 k+2 ... ..2 1 0 即k-i

代码

#include<cstdio>
#include<algorithm>
using namespace std; const int N=1e5+; struct p
{
int v,id,s;
} a[N];
bool cmp(p a,p b)
{
return a.v<b.v;
}
bool cmp1(p a,p b)
{
return a.id<b.id;
}
int n;
int main()
{
scanf("%d",&n);
for(int i=; i<=n; i++)
{
scanf("%d",&a[i].v);
a[i].id=i;
}
printf("YES\n");
sort(a+,a++n,cmp);
int k=n/;
if(n%) k++;
for(int i=; i<=k; i++)
{
a[i].s=;
a[i+k].s=a[i+k].v;
a[i+k*].s=k-i;
}
sort(a+,a++n,cmp1);
for(int i=; i<n; i++)
{
printf("%d ",a[i].s);
}
printf("%d\n",a[n].s);
for(int i=; i<n; i++)
{
printf("%d ",a[i].v-a[i].s);
}
printf("%d\n",a[n].v-a[n].s);
return ;
}

  

【CodeForces 297C】Splitting the Uniqueness的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【codeforces 754A】Lesha and array splitting

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  3. 【codeforces 750D】New Year and Fireworks

    time limit per test2.5 seconds memory limit per test256 megabytes inputstandard input outputstandard ...

  4. 【codeforces 766C】Mahmoud and a Message

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  6. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  7. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  8. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  9. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

随机推荐

  1. 2014 UESTC 暑前集训队内赛(2) 部分解题报告

    B.Cuckoo for Hashing 模拟题. 代码: #include <iostream> #include <cstdio> #include <cstring ...

  2. UVA 11573 Ocean Currents --BFS+优先队列

    采用优先队列做BFS搜索,d[][]数组记录当前点到源点的距离,每次出队时选此时eng最小的出队,能保证最先到达的是eng最小的.而且后来用普通队列试了一下,超时..所以,能用优先队列的,就要用优先队 ...

  3. two sum - leetcode

    Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...

  4. Android外部SD卡的读取

    package com.kevin.writeorreadfile1_1; import android.app.Activity; import android.bluetooth.le.ScanF ...

  5. web安全测试工具的局限性

    讨论安全漏洞的原理,谈谈工具的局限. 先说下扫描工具的原理: 扫描工具可以看做由两部分组成:爬虫+校验机构.爬虫的作用是搜集整个被采集对象的链接,然后校验机构对这些链接逐一进行验证. 说扫描工具的局限 ...

  6. java 14 -10 Calendar类以及练习

    Calendar:它为特定瞬间与一组诸如 YEAR.MONTH.DAY_OF_MONTH.HOUR 等 日历字段之间的转换提供了一些方法, 并为操作日历字段(例如获得下星期的日期)提供了一些方法. 1 ...

  7. Spring2.5与JDK8的集成问题

    Spring2.5不支持JDK8及其以上的版本,因为有一段校验JDK版本的代码,当JDK版本大于1.7之后,会识别成JDK1.4之前的.会报版本太低的错误. /* * Copyright 2002-2 ...

  8. py变量

        1, python以数据为主 x=2,是给数据2开辟了个空间, X指向了2 y=x ,即y指向了2 x=5 ,x重新赋值 但是y依旧是原来的

  9. php基础33:正则匹配-perl

    <?php //1.搜索数组中的相匹配的字符串 //preg_grep() 返回一个数组 $language = array("php","asp",&q ...

  10. [CareerCup] 2.7 Palindrome Linked List 回文链表

    2.7 Implement a function to check if a linked list is a palindrome. LeetCode上的原题,参见我之前的博客Palindrome ...