/*给出n个原始顺序的数,再给出要排成目标状态顺序,每次从第一个数列中选择三个,把这三个数中最右边的数放在最左边,然后其他两个数右
移一个单位,为你从原始状态能不能排序成目标状态。
本人YY的结论,从特殊到一般,虽然一般的只是手证了数值比较小的:结论应该就是1到n的n个数的全排列,分成相等的奇排序和偶排序,且个数一样,同个集合中的排列可以互相转换
比如1 2 3 4的全排1 2 3 4
1 4 2 3
1 3 4 2
4 1 3 2
4 2 1 3
4 3 2 1
2 4 3 1
2 1 4 3
2 3 1 4
3 4 1 2(可由4 1 3 2变成,一样的)
3 2 4 1
3 1 2 4
这个偶排序占了12个,其他十二个是奇排序
所以这道题直接比较两个数列的奇偶性
*/
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxn=;
int a[maxn],b[maxn],c[maxn];
int n;
struct point
{
int num,index;
}p[maxn];
int cmp(const point a,const point b)
{
return a.num<b.num;
}
int lowbit(int x)
{
return x&(-x);
}
void updata(int i,int x)
{
while(i<=n)
{
c[i]+=x;
i=i+lowbit(i);
}
}
int sum(int x)
{
int ans=;
while(x>)
{
ans+=c[x];
x=x-lowbit(x);
}
return ans;
}
int main()
{
int i,j;
while(scanf("%d",&n)!=EOF)
{
memset(c,,sizeof(c));
for(i=;i<=n;i++)
{
scanf("%d",&p[i].num);
p[i].index=i;
}
sort(p+,p+n+,cmp);
for(i=;i<=n;i++)
b[p[i].index]=i; int ans1=,ans2=;
for(i=;i<=n;i++)
{
updata(b[i],);
ans1=ans1+(sum(n)-sum(b[i]));//sum(p[i])是前面比b[i]小的数的个数
}
memset(c,,sizeof(c));
memset(p,,sizeof(p));
memset(b,,sizeof(b));
for(i=;i<=n;i++)
{
scanf("%d",&p[i].num);
p[i].index=i;
}
sort(p+,p+n+,cmp);
for(i=;i<=n;i++)
b[p[i].index]=i; for(i=;i<=n;i++)
{
updata(b[i],);
ans2=ans2+(sum(n)-sum(b[i]));
}
printf("%d %d\n",ans1,ans2);
if(ans1%==ans2%) printf("Possible\n");
else printf("Impossible\n");
}
return ;
}
PS:这道题置换群也可以破
有奇数个有偶数个元素的轮换就是不可以
有偶数个有偶数个元素的轮换就是可以

BNUOJ 26474 Bread Sorting的更多相关文章

  1. BNUOJ-26474 Bread Sorting 逆序对

    题目链接:http://www.bnuoj.com/bnuoj/problem_show.php?pid=26474 题意:给一个数列,可以对三个数操作:把最后一个数放到第一个,前两个数后移一位.问最 ...

  2. BNUOJ-26579 Bread Sorting YY

    题目链接:http://www.bnuoj.com/bnuoj/problem_show.php?pid=26579 考虑两个性质:蚂蚁的相对位置不变,蚂蚁碰撞时相当于对穿而过,然后排两次序就可以了. ...

  3. BNUOJ-29364 Bread Sorting 水题

    题目链接:http://www.bnuoj.com/bnuoj/problem_show.php?pid=29364 题意:给一个序列,输出序列中,二进制1的个数最少的数.. 随便搞搞就行了,关于更多 ...

  4. BNUOJ-29357 Bread Sorting 模拟

    题目链接:http://www.bnuoj.com/bnuoj/problem_show.php?pid=29357 直接模拟就可以了.. //STATUS:C++_AC_190MS_1884KB # ...

  5. NCPC 2012 Bread Sorting

    逆序对数的应用: 逆序对数的写法有,二分,树状数组,分治: 学习一下: 树状数组版: 代码: #include<cstdio> #include<cstring> #inclu ...

  6. BNUOJ 12756 Social Holidaying(二分匹配)

    题目链接:http://www.bnuoj.com/bnuoj/problem_show.php?pid=12756 Social Holidaying Time Limit: 3000ms Memo ...

  7. HDU Cow Sorting (树状数组)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2838 Cow Sorting Problem Description Sherlock's N (1  ...

  8. 1306. Sorting Algorithm 2016 12 30

    1306. Sorting Algorithm Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description One of the f ...

  9. 算法:POJ1007 DNA sorting

    这题比较简单,重点应该在如何减少循环次数. package practice; import java.io.BufferedInputStream; import java.util.Map; im ...

随机推荐

  1. 使用fetch-jsonp进行跨域以及参数的传递

    其实fetch-jsonp的官方文档里面已经写得很详细了,连接如下:https://github.com/camsong/fetch-jsonp:但是由于它本身没有多少demo,所以自己在上手的时候遇 ...

  2. 如何使用vue的axios结合PHP去上传文件

    我们在做表单提交的时候,往往会碰到一些表单提交的需求,那vue的axios与上传文件碰撞后不会出现什么不一样的火花吗,听我一一道来: 首先,我们需要对写一个vue的axios的表单提交,由于本人用的是 ...

  3. (一)微信小程序之模拟调用后台接口踩过的坑

    如下图标记的三个点 在调试过程中出现问题,特此记录. 1. 之前在浏览器测试接口习惯省略 http:// ,是因为浏览器默认有一个检测,在你输入的网址前面加http://,如果有就不加. 然而在微信小 ...

  4. AS3在函数内部移除监听(arguments.callee)

    scene.addEventListener(Event.ADDED_TO_STAGE, function():void { scene.removeEventListener(Event.ADDED ...

  5. 【BZOJ2118】墨墨的等式 最短路

    [BZOJ2118]墨墨的等式 Description 墨墨突然对等式很感兴趣,他正在研究a1x1+a2y2+…+anxn=B存在非负整数解的条件,他要求你编写一个程序,给定N.{an}.以及B的取值 ...

  6. 【BZOJ4101】[Usaco2015 Open]Trapped in the Haybales Silver 二分

    [BZOJ4101][Usaco2015 Open]Trapped in the Haybales (Silver) Description Farmer John has received a sh ...

  7. struts2的占位符*在action中的配置方法

    转自:https://blog.csdn.net/u012546338/article/details/68946633 在配置<action> 时,可以在 name,class,meth ...

  8. centos7安装mysql(MariaDB)

    1.centos7现状: 新系统无法再使用yum install mysql-server来安装mysql,因为已使用mariadb代替mysql. 2.安装mariadb: [root@localh ...

  9. Android - XML序列化

    1.xml文件的序列化:采用XmlSerializer来实现XML文件的序列化.相比传统方式,更高效安全 MainActivity.java package com.example.test_buil ...

  10. 详解Go语言中的屏蔽现象

    在刚开始学习Go语言的过程中,难免会遇到一些问题,尤其是从其他语言转向Go开发的人员,面对语法及其内部实现的差异,在使用Go开发时也避免不了会踩"坑".本文主要针对Go设计中的屏蔽 ...