【CodeForces 297C】Splitting the Uniqueness
题意
序列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的更多相关文章
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 754A】Lesha and array splitting
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 750D】New Year and Fireworks
time limit per test2.5 seconds memory limit per test256 megabytes inputstandard input outputstandard ...
- 【codeforces 766C】Mahmoud and a Message
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
随机推荐
- putty 访问 vmware中ubuntu 方法
putty访问虚拟机 从宿主机中用putty连接虚拟机中的Ubuntu. putty默认使用ssh方式连接,这需要在Ubuntu Server中安装ssh服务.使用命令sudo apt-get ...
- AutoIT 实现Firefox上传文件
Firefox浏览器文件上传代码如下: ;upload file Func _UploadFile($file) AutoItSetOption("WinTitleMatchMode&quo ...
- VC2010中去掉红绝下划线
1. 在VC2010 的tools/中找到editior. 已经找到c/c++->advanced->IntelliSense->Disable IntelliSence->T ...
- 用mel编写自定义节点的属性编辑器界面
用mel编写自定义节点的属性编辑器界面比较麻烦,而且网上例子又少,下面给出一个范例,说明基本的格式 // 初始化节点时调用 global proc initControl(string $attrNa ...
- iOS中使用RSA对数据进行加密解密
RSA算法是一种非对称加密算法,常被用于加密数据传输.如果配合上数字摘要算法, 也可以用于文件签名. 本文将讨论如何在iOS中使用RSA传输加密数据. 本文环境 mac os openssl-1.0. ...
- Android应用性能优化之使用SparseArray替代HashMap
HashMap是java里比较常用的一个集合类,我比较习惯用来缓存一些处理后的结果.最近在做一个Android项目,在代码中定义这样一个变量,实例化时,Eclipse却给出了一个 performanc ...
- R语言利器之ddply和aggregate
ddply和aggregate是两个用来整合数据的功能强大的函数. aggregate(x, ...) 关于aggregate()函数的使用在<R语言实战>中P105有简单描述,这里重新说 ...
- How to configure SRTM elevations in WorldWind WMS
In this thread I will try to explain how to serve SRTM elevations using NASA WorldWind WMS. ! Import ...
- 反射中使用 BindingFlags.IgnoreCase
我们经常需要通过反射来调用目标对象的方法或获取/设置目标对象的属性,Type.InvokeMember 方法签名如下: public object InvokeMember(string name,B ...
- pandas 时间序列resample
resample与groupby的区别:resample:在给定的时间单位内重取样groupby:对给定的数据条目进行统计 函数原型:DataFrame.resample(rule, how=None ...