#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 ...
随机推荐
- Windows 下 C/C++ 多线程编程入门参考范例
#include <windows.h> #include <iostream> using namespace std; DWORD WINAPI myThread(LPVO ...
- Hive开发中使用变量的两种方法
在使用hive开发数据分析代码时,经常会遇到需要改变运行参数的情况,比如select语句中对日期字段值的设定,可能不同时间想要看不同日期的数据,这就需要能动态改变日期的值.如果开发量较大.参数多的话, ...
- 【6.12校内test】T2 子集
这道题大概是这三道题里最简单的啦 但这阻止不了我废的脚步 [问题描述] 对于 n=4 时,对应的集合 s={4,3,2,1},他的非空子集有 15 个依次如下: {1} {2} {1,2} {3} { ...
- Python中的四种数据结构
Python中的内置数据结构(Built-in Data Structure):列表list.元组tuple.字典dict.集合set,涵盖的仅有部分重点. 目录: 一.列表list 二.元组tup ...
- spring boot引入thymeleaf导致中文乱码
加上下面这句代码 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" / ...
- 教你搭建基于typescript的vue项目
自尤大去年9月推出vue对typescript的支持后,一直想开箱尝试,对于前端sr来说,vue的顺滑加上ts的面向对象,想着就非常美好~ 终于在两个月前,找到了个机会尝试了一把vue+ts的组合. ...
- TableView 两种Style Plain and Group 区别以及进阶使用
一.UITableViewStylePlain 1.有多段时 段头停留(自带效果) 2.没有中间的间距和头部间距(要想有的重写UITableViewCell /UITableViewHeaderFoo ...
- ubuntu apache https设置
上篇文章已经描述过怎么生成证书,点击这里,直接写怎么设置 1.apache加载ssl模块, # a2enmod ssl 2.启动ssl站点 #a2ensite default-ssl 3.加入监听端口 ...
- PHP出现502解决方案
nginx 出现 502 有很多原因,但大部分原因可以归结为资源数量不够用,也就是说后端 php-fpm 处 理有问题,nginx 将正确的客户端请求发给了后端的 php-fpm 进程,但是因为 ph ...
- react-native启动时红屏报错:Unable to load script.Make sure you're either running a metro server or that ....
一.报错信息内容 我是在Android Studio中运行启动react-native项目时报的这个错误 1.报错提示:Unable to load script.Make sure you're e ...