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 ...
随机推荐
- 夺命雷公狗---DEDECMS----15dedecms首页栏目列表页导航部分完成
我们在点击导航页面的连接时候我们需要我们的连接跳到指定的模版页面,而不是随便跳到一个指定的A连接标签: 所以我们首先要将前端给我们的栏目列表模版拷贝到目录下,然后就可以创建栏目列表页面了,但是名字我们 ...
- java 网络编程(四)----UDP进阶篇聊天小程序
设计要求:单线程模式,客户端只发送数据,数据的来源为键盘录入,服务器端只接收数据,当客户端发送886的时候,客户端和服务器端都退出. 1. 发送端: public class Send impleme ...
- zw版【转发·台湾nvp系列Delphi例程】HALCON OverpaintRegion1
zw版[转发·台湾nvp系列Delphi例程]HALCON OverpaintRegion1 unit Unit1;interfaceuses Windows, Messages, SysUtils, ...
- yii2语言设置
1.父配置文件在yii2/base/Application中的$language="en-US", 修改项目的语言可以修改项目的配置文件main.php中加'language'=& ...
- form 表单jquery验证插件使用
第一部分:表单样式 <form action="#" method="post" id="regist"> <tabl ...
- Android剪切板传递数据传递序列化对象数据
一.剪切板的使用介绍 1. 剪切板对象的创建 使用剪切板会用到,ClipboardManager对象,这个对像的创建不可以使用构造方法,主要是由于没有提供public的构造函数(单例模式),需要使用A ...
- iOS:UITableView 方法 属性
参考:https://developer.apple.com/library/iOS/documentation/UIKit/Reference/UITableView_Class/Reference ...
- iOS 第一次安装应用,拒绝相机调用,页面卡死的解决方案
void (^allowBlock)() = ^{ UIImagePickerController *imagePicker = [[UIImagePickerController alloc] in ...
- easyui常现错误
1.easyui-tabs:当data-options的属性设置为true时,其tab内部的内容显示不出来. 2.设置easyui-panel的title格式及字体大小无效 解决方法:在设置title ...
- Yahoo! s4和Twitter storm的粗略比较