【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 [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
随机推荐
- leetcode : valid binary search tree
不能通过 当元素中 有 val == INT_MAX 或者 val == INT_MIN /** * Definition for a binary tree node. * struct Tree ...
- Windows系统安装Oracle 11g客户端
一.下载 http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html以下网址来源此官方下载页网 ...
- BUG描述规范
BUG描述规范 一. 目的与适用范围 1.1 目的 报告软件测试错误的目的是为了保证修复错误的人员可以明确报告的错误,从而有利于分析错误产生的原因,定位错误,然后修正之.因此,报告软件测试错误的基本要 ...
- 关于Java多态
什么是多态 同一个实现接口,使用不同的实例而执行不同的操作 子类转换成父类的规则: *将一个父类的引用指向一个子类对象时,称为上转型,自动进行类型转换 *此时通过父类引用变量调用的方法是子类覆盖或继承 ...
- 房产企业如何借助K2 BPM脱颖而出?
点击这里,查看完整版房地产行业的流程管理解决方案.
- 【Spring开发】—— Spring注入静态变量
今天碰到一个问题,我的一个类提供了几种静态方法,静态方法需要另外一个类的实例提供处理,因此就写出了这样的代码: Class aa{ private static XXX xxx; xxx = Bean ...
- Microsoft Visual Studio 正忙
简介:Microsoft Visual Studio 正忙,Microsoft Visual Studio 正在等待内部操作完成.如果经常在正常使用的情况下遇到此延迟, 请向Microsoft报告此情 ...
- chrome http Request Header 修改插件
chrome http Request Header 修改插件 2013-05-31 11:03:03| 分类: JavaScript | 标签:chrome extensions chang ...
- VBS操作Excel常见方法
VBS操作Excel常见方法 作者: 字体:[增加 减小] 类型:转载 时间:2009-11-13我要评论 VBS控制Excel常见方法,需要的朋友可以参考下. dim oExcel,oWb,oShe ...
- [CareerCup] 7.1 Basketball Shooting Game 投篮游戏
7.1 You have a basketball hoop and someone says that you can play one of two games. Game 1: You get ...