题目链接:F、Swaps Again

题意:

有两个长度为n的数组a和数组b,可以选择k(1<=k<=n/2)交换某一个数组的前缀k和后缀k,可以交换任意次数,看最后是否能使两个数组相等

可以输出yes,否则输出no

题解:

。。。这道题我真没想到这样写

例如一个序列1,2,3,4,5.你交换一次(怎么交换就不说了,能看出来),5,2,3,4,1,再交换一次4,1,3,5,2.

你会发现一个规律(反正我没发现),对称位置的元素依然是最开始的元素,就比如没交换前1和5相对称,再交换了多次之后1还是和5处于对称位置

那么如果b序列可以通过a序列交换得到,那么肯定某个数的对应元素肯定在两个数组中都一样

STL中pair容器的用法

代码:

 1 #include<stdio.h>
2 #include<algorithm>
3 #include<iostream>
4 #include<string>
5 #include<queue>
6 #include<deque>
7 #include<string.h>
8 #include<map>
9 #include <iostream>
10 #include <math.h>
11 using namespace std;
12 typedef long long ll;
13 const int maxn=500+10;
14 int a[maxn],b[maxn];
15 pair<int,int> p1[maxn],p2[maxn];
16 int main()
17 {
18 int t;
19 scanf("%d",&t);
20 while(t--)
21 {
22 int n;
23 memset(p1,0,sizeof(p1));
24 memset(p2,0,sizeof(p2));
25 bool flag=0;
26 scanf("%d",&n);
27 for(int i=1; i<=n; i++)
28 {
29 scanf("%d",&a[i]);
30 }
31 for(int i=1; i<=n; i++)
32 {
33 scanf("%d",&b[i]);
34 }
35 if(n%2==1&&a[n/2+1]!=b[n/2+1]) //中间这位不能变
36 {
37 flag=1;
38 }
39 for(int i=1; i<=n/2; i++)
40 {
41 p1[i]= {max(a[i],a[n-i+1]),min(a[i],a[n-i+1])};
42 p2[i]= {max(b[i],b[n-i+1]),min(b[i],b[n-i+1])};
43 }
44 sort(p1+1,p1+1+n/2);
45 sort(p2+1,p2+1+n/2);
46 for(int i=1; i<=n/2; i++)
47 {
48 if(p1[i]!=p2[i])
49 {
50 flag=1;
51 }
52 }
53 if(flag==0)
54 {
55 printf("yes\n");
56 }
57 else
58 {
59 printf("no\n");
60 }
61 }
62 return 0;
63 }

Codeforces Round #648 (Div. 2) F. Swaps Again的更多相关文章

  1. Codeforces Round #485 (Div. 2) F. AND Graph

    Codeforces Round #485 (Div. 2) F. AND Graph 题目连接: http://codeforces.com/contest/987/problem/F Descri ...

  2. Codeforces Round #486 (Div. 3) F. Rain and Umbrellas

    Codeforces Round #486 (Div. 3) F. Rain and Umbrellas 题目连接: http://codeforces.com/group/T0ITBvoeEx/co ...

  3. Codeforces Round #501 (Div. 3) F. Bracket Substring

    题目链接 Codeforces Round #501 (Div. 3) F. Bracket Substring 题解 官方题解 http://codeforces.com/blog/entry/60 ...

  4. Codeforces Round #499 (Div. 1) F. Tree

    Codeforces Round #499 (Div. 1) F. Tree 题目链接 \(\rm CodeForces\):https://codeforces.com/contest/1010/p ...

  5. Codeforces Round #376 (Div. 2)F. Video Cards(前缀和)

    题目链接:http://codeforces.com/contest/731/problem/F 题意:有n个数,从里面选出来一个作为第一个,然后剩下的数要满足是这个数的倍数,如果不是,只能减小为他的 ...

  6. Codeforces Round #271 (Div. 2) F. Ant colony (RMQ or 线段树)

    题目链接:http://codeforces.com/contest/474/problem/F 题意简而言之就是问你区间l到r之间有多少个数能整除区间内除了这个数的其他的数,然后区间长度减去数的个数 ...

  7. Codeforces Round #325 (Div. 2) F. Lizard Era: Beginning meet in the mid

    F. Lizard Era: Beginning Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...

  8. Codeforces Round #271 (Div. 2) F题 Ant colony(线段树)

    题目地址:http://codeforces.com/contest/474/problem/F 由题意可知,最后能够留下来的一定是区间最小gcd. 那就转化成了该区间内与区间最小gcd数相等的个数. ...

  9. Codeforces Round #479 (Div. 3) F. Consecutive Subsequence (简单dp)

    题目:https://codeforces.com/problemset/problem/977/F 题意:一个序列,求最长单调递增子序列,但是有一个要求是中间差值都是1 思路:dp,O(n)复杂度, ...

随机推荐

  1. LeetCode557 反转字符串中的单词 III

    给定一个字符串,你需要反转字符串中每个单词的字符顺序,同时仍保留空格和单词的初始顺序. 示例 1: 输入: "Let's take LeetCode contest" 输出: &q ...

  2. JVM-Class文件的结构

    Class类文件的结构 Class文件是一株以8个字节为单位的二进制流.各个数据项目严格按照顺序紧凑的排列在文件之中,中间没有任何的分隔符,当遇到占用的空间大于8个字节时,会按照高位在前的方式进行分割 ...

  3. SpringBoot整合Shiro完成验证码校验

    SpringBoot整合Shiro完成验证码校验 上一篇:SpringBoot整合Shiro使用Redis作为缓存 首先编写生成验证码的工具类 package club.qy.datao.utils; ...

  4. Linux简单Shell脚本监控MySQL、Apache Web和磁盘空间

    Linux简单Shell脚本监控MySQL.Apache Web和磁盘空间 1. 目的或任务 当MySQL数据库.Apache Web服务器停止运行时,重新启动运行,并发送邮件通知: 当服务器磁盘的空 ...

  5. 安装MySQL数据库(在Windows下通过zip压缩包安装)

    安装MySQL 这里建议大家使用压缩版,安装快,方便.不复杂. 软件下载 mysql5.7 64位下载地址: https://dev.mysql.com/get/Downloads/MySQL-5.7 ...

  6. mysql—information_schema数据库

    一.介绍 MySQL中有一个默认数据库名为information_schema,在MySQL中我们把 information_schema 看作是一个数据库,确切说是信息数据库.其中保存着关于MySQ ...

  7. powershell中的cmdlet命令

    Add-Computer 向域或工作组中添加计算机. Add-Content 向指定的项中添加内容,如向文件中添加字词. Add-History 向会话历史记录追加条目. Add-Member 向 W ...

  8. Py-时间,随机,os,sys,jsonpickle序列化,shelve,xml模块

    内置模块 1.时间模块 第一:time.time()是时间戳 时间戳默认是 从1970年到现在过的秒数,是一个很长的数值它可以做时间的计算以及显示 第二:localtime() 获取当前的时间,按元组 ...

  9. 图像Demosaic算法及其matlab实现

    由于成本和面积等因素的限定,CMOS/CCD在成像时,感光面阵列前通常会有CFA(color filter array),如下图所示,CFA过滤不同频段的光,因此,Sensor的输出的RAW数据信号包 ...

  10. .NET Core部署到linux(CentOS)最全解决方案,入魔篇(使用Docker+Jenkins实现持续集成、自动化部署)

    通过前面三篇: .NET Core部署到linux(CentOS)最全解决方案,常规篇 .NET Core部署到linux(CentOS)最全解决方案,进阶篇(Supervisor+Nginx) .N ...