#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 ...
随机推荐
- linux free 命令 查看内存使用情况
查看Linux服务器下的内存使用情况,可以使用命令free -m [root@localhost ~]$ free // 以KB为单位显示内存使用情况 [root@localhost ~]$ free ...
- Linux 根据端口快速停止服务并启动的办法
0. 需要使用 lsof 的命令, 如果linux 上面没有安装的话 需要自行安装 yum install lsof or apt-get install lsof 1. 先根据端口查进程号 [roo ...
- jsp运行环境的安装和配置
1.JDK的安装和配置 1)下载jdk,我下载的是1-jdk-6u26-windows-i586.exe,放在D:\StudySystem\JavaWeb\jdk目录下. 2)安装jdk,直接你下载的 ...
- Django查询数据库返回字典dict数据
个人观点: 个人认为,在Django项目中, 开发团队为了让使用该框架的用户都使用自带的序列化功能,从而让框架中的SQL返回值很不直观,对于直接使用SQL语句的用户很犯难. 解决: from djan ...
- Gym 101466(完整)
题目链接 :点击此处 ## Problem A 题意: 给你n个数,重定义两个数之间的加法不进位,求这些数中两个数相加的最大值和最小值. 题解: 字典树.我们首先将前i-1为放入字典树中,然后在查询第 ...
- 11、权重残差图、RLE和NUSE
affyPLM包可以对芯片原始数据进行拟合回归,最后得到芯片权重(Weights)残差(Residuals)图.相对对数表达(RLE,Relative log expression)箱线图.相对标准差 ...
- C# System.Reflection (反射)
在使用.NET创建的程序或组件时,元数据(metadata)和代码(code)都存储于“自成一体”的单元中,这个单元称为装配件.我们可以在程序运行期间访问这些信息. 在System.Reflectio ...
- crm---本项目的权限控制模式
一:url权限: 最底层的权限控制,,缺点在与没有预判的机制,造成客户体验下降. 前提: 为controller中的每一个方法(即资源)定义一个资源(Resource)名称,,该 ...
- TableView 两种Style Plain and Group 区别以及进阶使用
一.UITableViewStylePlain 1.有多段时 段头停留(自带效果) 2.没有中间的间距和头部间距(要想有的重写UITableViewCell /UITableViewHeaderFoo ...
- laravel-admin Field type [editor] does not exist.
把App/admin中的bootstrap.php 里边的Encore\Admin\Form::forget(['map', 'editor']);注释掉就行了 解决网址:http://tieba.b ...