#418 Div2 Problem B An express train to reveries (构造 || 全排列序列特性)
题目链接:http://codeforces.com/contest/814/problem/B
题意 : 有一个给出两个含有 n 个数的序列 a 和 b, 这两个序列和(1~n)的其中一个全排列序列 p 只有一个元素不同, 要求你找出任意满足这个条件的序列 p
分析 : 全排列有个特点, 就是各个元素各不相同, 只要改变了其中的一个元素(当然改变后还是在1~n内), 那序列当中必有重复的元素, 而且在1~n中必定有一个数不会出现在这个序列中。很显然的一个特点, 如果没有想到的话, 这题可能就比较难看出解法了。实际上a 和 b就是这样改变了一个元素后的序列, 所以只要找出 a 中的两个相同元素所在的位置, 分别轮流替换成未出现的元素和原来的元素, 然后去和b匹配一下是否满足题意, 如果满足则就是第一种组合, 否则就是第二种了。例如 1 2 2 3 , 那就可以变化成 1 2 4 3 和 1 4 2 3去匹配b。
瞎搞 : 想来想去想了挺久, 往错的方向想了很久, 最后情况分类实在太多, 自己也晕了, 打出来也就只通过了21个点, 还是弱啊........
#include<bits/stdc++.h>
using namespace std;
map<int, int> m;
int n;
], b[], vis[], c[];
bool Check()
{
;
; i<=n; i++){
if(c[i]!=b[i]) diffb++;
}
) return true;
return false;
}
int main(void)
{
scanf("%d", &n);
int fir, sec;
memset(vis, false, sizeof(vis));
int index1, index2;
; i<=n; i++){
scanf("%d", &a[i]);
vis[a[i]] = true;
if(m.count(a[i])){
index1 = m[a[i]];
index2 = i;
fir = a[i];
}
m[a[i]] = i;
}
; i<=n; i++){
scanf("%d", &b[i]);
if(i!=index1 || i!=index2) c[i] = a[i];
}
; i<=n; i++){
if(!vis[i] && i!=fir){
sec = i;
break;
}
}
c[index1] = fir, c[index2] = sec;
if(Check()){
; i<=n; i++){
printf("%d ", c[i]);
}
puts("");
;
}
c[index1] = sec, c[index2] = fir;
; i<=n; i++){
printf("%d ", c[i]);
}
puts("");
;
}
#418 Div2 Problem B An express train to reveries (构造 || 全排列序列特性)的更多相关文章
- Codeforces Round #418 (Div. 2) B. An express train to reveries
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- Codeforces - 814B - An express train to reveries - 构造
http://codeforces.com/problemset/problem/814/B 构造题烦死人,一开始我还记录一大堆信息来构造p数列,其实因为s数列只有两项相等,也正好缺了一项,那就把两种 ...
- B. An express train to reveries
B. An express train to reveries time limit per test 1 second memory limit per test 256 megabytes inp ...
- An express train to reveries
An express train to reveries time limit per test 1 second memory limit per test 256 megabytes input ...
- codeforces 814B.An express train to reveries 解题报告
题目链接:http://codeforces.com/problemset/problem/814/B 题目意思:分别给定一个长度为 n 的不相同序列 a 和 b.这两个序列至少有 i 个位置(1 ≤ ...
- CF814B An express train to reveries
思路: 模拟,枚举. 实现: #include <iostream> using namespace std; ; int a[N], b[N], cnt[N], n, x, y; int ...
- codeforces round 418 div2 补题 CF 814 A-E
A An abandoned sentiment from past 水题 #include<bits/stdc++.h> using namespace std; int a[300], ...
- #333 Div2 Problem B Approximating a Constant Range(尺取法)
题目:http://codeforces.com/contest/602/problem/B 题意 :给出一个含有 n 个数的区间,要求找出一个最大的连续子区间使得这个子区间的最大值和最小值的差值不超 ...
- #417 Div2 Problem B Sagheer, the Hausmeister (DFS && 枚举)
题目链接:http://codeforces.com/contest/812/problem/B 题意 : 给出一个 n (1 ≤ n ≤ 15)层的教学楼, 每一层楼包含 m (1 ≤ m ≤ 10 ...
随机推荐
- 【神经网络与深度学习】caffe+VS2013+Windows无GPU快速配置教程
首先来一波地址: happynear大神的第三方caffe:http://blog.csdn.net/happynear/article/details/45372231 Neil Z大神的第三方ca ...
- 【嵌入式开发】Raspberry Pi 树莓派性能测试
Raspberry Pi 树莓派性能测试 目录: CPU Linpack基准测试 源码 编译/运行 结果 Whetstone/Dhrystone综合基准测试 源码 编译/运行 结果 OpenSSL安全 ...
- MFC,QT与WinForm,WPF简介
编程语言的组成编程语言做为一种语言自然和英语这些自然语言有类似的地方.学英语时我们知道要先记26个字母,然后单词及其发音,接下来就是词组,句子.反正简单的说就是记单词,熟悉词法,句法.接下来就是应用了 ...
- UDP协议&socketserver模块
UDP协议&socketserver模块 一.UDP协议 1.1 UDP实现简单通信 服务器 ------------------------------------------------- ...
- 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 H. Skiing
题意:在这个寒假中,鲍勃有计划在山区度假胜地滑雪.这个滑雪胜地有M个不同的滑雪道和N个不同的标志位于那些转弯处点.从第S标记到第T标志的第i路径具有长度L.每个路径必须遵循降低高度的原则,起点必须严格 ...
- [React] react-interview-01
1.render 函数中 return 如果没有使用()会有什么问题? 我们在使用 JSX 语法书写 react 代码时,babel 会将 JSX 语法编译成 js,同时会在每行自动添加分号(:),如 ...
- doT学习(三)之实战
案例一: <html> <head> <script id="headertmpl" type="text/x-dot-template&q ...
- mysql数据库基础命令(一)
用户与权限 创建用户 mysql>create user test identified by 'BaC321@#'; 修改密码 ##5.5版本及以前的命令 mysql>set passw ...
- MWPhotoBrowser.bundle: bundle format unrecognized, invalid, or unsuitable
今天在github下载了MWPhotoBrowser的demo想跑一下,却发现报了MWPhotoBrowser.bundle: bundle format unrecognized, invalid, ...
- oracle使用between and边界问题
如果是只查询某两个月之间的数据,会默认从每个月的1号开始查,包前包后 eg:select * from test_hsj where regdate between to_date('2015-05' ...