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 ...
随机推荐
- [javascript] ajaxfileupload.js 跨域上传文件
原文地址: http://www.ueffort.com/jqueryajaxfileupload-js-duo-wen-jian-shang-chuan-chuan-zhi-kua-yu/ 跨域 这 ...
- 想学习一下CSS函数
好像原来都是用前后端代码实现的功能,如今CSS3已经吸纳为标准,使用简单的选择器就可以实现了.
- angularjs 相关资料
1.angularjs 框架结构 bootstrap process :http://www.oschina.net/translate/angularjs-the-next-big-thing?pr ...
- tomcat支持的websocket服务
首发:个人博客 在tomcat7之后的版本,写个websocket服务程序非常容易——如以下代码所示,当客户端建立了一个连接并发送了一些什么内容到服务器,服务器将每隔两秒返回一个字符串“world”. ...
- 161125、Java网络编程之统一资源定位符URL
统一资源定位符URL(Uniform Resource Locator)是www客户机访问Internet时用来标识资源的名字和地址.超文本链路由统一资源定位符URL维持.URL的格式是: <M ...
- JBuilder链接sql server数据库
加载你的jdbc的驱动 一.将jdbc驱动解压到一个指定的目录,例如:c:\sql_server_jdbc, 其中包含三个驱动文件:msbase. ...
- loading等待载入正在加载的动画GIF图片圆形图标
http://www.wtoutiao.com/p/GdfbdM.html
- Redis 转
Redis 简介 Redis实践 Redis命令总结
- fprintf 读入%s,要注意
eg 文件内容faninfd 14 "%s %d",会把整行内容放到%s 而%d是乱码 ps: 文件内容是 1,2,3 “%d,%d,%d” 文件内容是1:2:3 ...
- oracle初次使用连接不上
问题描述: win10下,cmd运行 输入sqlplus报一下错误 SP2-1503: 无法初始化 Oracle 调用界面 SP2-0152: ORACLE 不能正常工作 解决办法 cmd右键--以管 ...