题目链接:http://www.bnuoj.com/bnuoj/problem_show.php?pid=26474

  题意:给一个数列,可以对三个数操作:把最后一个数放到第一个,前两个数后移一位。问最后能否到达相应的目标序列。。

  先考虑三个数A B C,变换后两种情况B C A和C A B,可以证得(列举3个数的大小情况,枚举证),这三个序列变换后的逆序对个数的奇偶性是相同的,而且只有这3个序列相同,所以A B C只能到达与之奇偶相同的序列,而且是全部能到达。那么多个数的情况也是一样的,就是多个3元组的扩展。因此如果变换后的逆序奇偶性相同,那么有解,否则无解。。

 //STATUS:C++_AC_868MS_2220KB
#include <functional>
#include <algorithm>
#include <iostream>
//#include <ext/rope>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
//#include <map>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,102400000")
//using namespace __gnu_cxx;
//define
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define PI acos(-1.0)
//typedef
typedef long long LL;
typedef unsigned long long ULL;
//const
const int N=;
const int INF=0x3f3f3f3f;
const int MOD=1e9+,STA=;
//const LL LNF=1LL<<60;
const double EPS=1e-;
const double OO=1e15;
const int dx[]={-,,,};
const int dy[]={,,,-};
const int day[]={,,,,,,,,,,,,};
//Daily Use ...
inline int sign(double x){return (x>EPS)-(x<-EPS);}
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T lcm(T a,T b,T d){return a/d*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);}
template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);}
template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));}
template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));}
//End int num[N],temp[N];
int n;
int ans; void sort(int l,int r)
{
if(l==r)return;
int i,j,k,mid=(l+r)>>;
sort(l,mid);
sort(mid+,r);
for(i=k=l,j=mid+;i<=mid && j<=r;){
if(num[i]<num[j]){
ans=(ans+j-mid-)&;
temp[k++]=num[i++];
}
else temp[k++]=num[j++];
}
while(i<=mid){
ans=(ans+j-mid-)&;
temp[k++]=num[i++];
}
while(j<=r)
temp[k++]=num[j++];
for(i=l;i<=r;i++)
num[i]=temp[i];
} int main()
{
// freopen("in.txt","r",stdin);
int i,j,ok;
while(~scanf("%d",&n))
{
ok=ans=;
for(i=;i<n;i++)
scanf("%d",&num[i]);
sort(,n-);
ok=ans;
ans=;
for(i=;i<n;i++)
scanf("%d",&num[i]);
sort(,n-);
ok^=ans; printf("%s\n",ok?"Impossible":"Possible");
}
return ;
}

最新文章

  1. solr_架构案例【京东站内搜索】(附程序源代码)
  2. JDBC数据库访问操作的动态监测 之 p6spy
  3. Scala 笔记
  4. GeoEvent使用问题及解决方法整理
  5. Tensorflow学习笔记1:Get Started
  6. [转载] HTTP 协议漫谈
  7. HTML笔记1
  8. 编写一个函数,接受三个string参数,s,oldVal和newVal。使用迭代器及insert和erase函数将s中所有oldVal替换为newVal。测试你的程序,用他替换通用的简写形式,如,将“tho”,将“”“”
  9. PAT-乙级-1053. 住房空置率 (20)
  10. 我的第一篇——nginx+naxsi总结篇1
  11. 数学(矩阵乘法):HDU 4565 So Easy!
  12. 集成支付宝SDK遇到的坑
  13. jquery.ajax和Ajax 获取数据
  14. Installing SSL on CentOS | My Virtual Time Capsule
  15. hdu4771 Stealing Harry Potter&amp;#39;s Precious
  16. 转载:MyEclipse安装插件的几种方法
  17. (转)JVM内存组成及分配
  18. 用python3读CSV文件,出现UnicodeDecodeError: &#39;utf-8&#39; codec can&#39;t decode byte 0xd0 in position 0: invalid con
  19. 使用Phalcon框架开发一个简易的博客系统
  20. Java的selenium代码随笔(3)

热门文章

  1. 互斥锁Mutex与信号量Semaphore的区别
  2. Error building Player: CommandInvokationFailure: Failed to re-package resources. See the Console for details. ShareSDK 也有这种错误
  3. 关于Application.Lock和Lock(obj)
  4. 使用typeid(变量或类型).name()来获取常量或变量的类型---gyy整理
  5. 【HDOJ】3601 Coach Yehr’s punishment
  6. Is there a way for me to run Adb shell as root without typing in &#39;su&#39;?
  7. 如何把Excel另存为XML格式文件(快速转换)
  8. BZOJ_1019_[SHOI2008]_汉诺塔_(DP)
  9. 了解AngularJS $resource
  10. Linux power supply class hacking