UVALive 6508 Permutation Graphs
Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu
#include<stdio.h>
#include<string.h> int temp[],a[],b[],c[],b1[];
long long num; void merg_sort(int a[],int l,int r)
{
int i,j,len=r-l,p1,p2;
if(len<=)
return;
int mid=l+len/;
merg_sort(a,l,mid);
merg_sort(a,mid,r);
p1=l,p2=mid;
for(i=l;i<r;i++)
{
if(p1==mid)
{
temp[i]=a[p2];
p2++;
}
else if(p2==r)
{
temp[i]=a[p1];
p1++;
}
else
{
if(a[p1]<=a[p2])
{
temp[i]=a[p1];
p1++;
}
else
{
temp[i]=a[p2];
p2++;
num=num+mid-p1;
}
}
}
for(i=l;i<r;i++)
a[i]=temp[i];
return;
} int main()
{
int T;
int n,i,j,k;
scanf("%d",&T);
while(T--)
{
num=;
scanf("%d",&n);
for(i=;i<=n;i++)
scanf("%d",&b[i]);
for(i=;i<=n;i++)
b1[b[i]]=i; for(i=;i<=n;i++)
scanf("%d",&c[i]);
for(i=;i<=n;i++)
a[i]=b1[c[i]]; /*for(i=1;i<=n;i++)
printf("%d ",a[i]);*/
merg_sort(a,,n+);
printf("%lld\n",num);
}
return ;
}
UVALive 6508 Permutation Graphs的更多相关文章
- 逆序数 UVALive 6508 Permutation Graphs
题目传送门 /* 题意:给了两行的数字,相同的数字连线,问中间交点的个数 逆序数:第一行保存每个数字的位置,第二行保存该数字在第一行的位置,接下来就是对它求逆序数 用归并排序或线段树求.想到了就简单了 ...
- UVaLive 11525 Permutation (线段树)
题意:有一个由1到k组成的序列,最小是1 2 … k,最大是 k k-1 … 1,给出n的计算方式,n = s0 * (k - 1)! + s1 * (k - 2)! +… + sk-1 * 0!, ...
- UVALIVE 4556 The Next Permutation
4556 The Next PermutationFor this problem, you will write a program that takes a (possibly long) str ...
- Permutation Sequence
The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- [LeetCode] Palindrome Permutation II 回文全排列之二
Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empt ...
- [LeetCode] Palindrome Permutation 回文全排列
Given a string, determine if a permutation of the string could form a palindrome. For example," ...
- [LeetCode] Permutation Sequence 序列排序
The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- [LeetCode] Next Permutation 下一个排列
Implement next permutation, which rearranges numbers into the lexicographically next greater permuta ...
- Leetcode 60. Permutation Sequence
The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
随机推荐
- zw版【转发·台湾nvp系列Delphi例程】HALCON 3D Position Of Circles
zw版[转发·台湾nvp系列Delphi例程]HALCON 3D Position Of Circles procedure TForm1.action();var ho_Image, ho_Elli ...
- jQuery触发<a>标签的点击事件后URL不跳转的解决办法
有HTML代码如下: <a id="workFrame" href="pages/work.html" target="FrameBox&quo ...
- 我的AutoCAD二次开发之路 (一)
原帖地址 http://379910987.blog.163.com/blog/static/33523797201011184552167/ 今天在改代码的时候,遇到了AddVertexAt方法的用 ...
- java类的访问权限
1.解析 Java有四种访问权限, 其中三种有访问权限修饰符,分别为private,public和protected,还有一种不带任何修饰符. private: Java语言中对访问权限限制的最窄的修 ...
- VMWare联网
VMWare提供了三种工作模式,它们是bridged(桥接模式).NAT(网络地址转换模式)和host-only(主机模式). 如果你想利用VMWare在局域网中新建一个独立的虚拟服务器,为局域网用 ...
- TI CC2541的引脚中断.
- jenkins+jmeter+ant搭建接口测试平台
接口测试的重点是检查数据的交换,传递和控制管理过程以及系统间的相互逻辑依赖关系. 接口测试的流程 项目启动后,测试人员要尽早拿到接口测试文档. 开始编写接口测试用例 将接口测试用例部署到持续集成的测试 ...
- FTP上传类
using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Net;usi ...
- activeMQ下载,安装,启动,关闭
1.新建一个文件夹activeMQ mkdir /server 2.授权 chmod 777 /server 3.下载activeMQ安装包,拷贝到/activeMQ目录下 apache-a ...
- html状态码与缓存学习
当浏览器访问一个页面时,浏览者的浏览器会向网页所在的服务器发送请求.当浏览器接收并显示网页前,此网页所在的服务器会返回一个包含HTTP状态码的信息头(server header)用以响应浏览器的请求. ...