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 ...
随机推荐
- python—类对象和实例对象的区别
最近在对RF的通讯层的模块进行封装,需要将之前放在类似main里面的一个方法,如下所示:这段代码是开发提供,用于接口测试,模拟底层通讯,具体的通讯是在dll内,python这边只是做了个封装让RF进行 ...
- .net web弹出对话框
Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('请输入 ...
- SQl中drop与truncate的区别
在对SQL的表操作时,我们因不同的需求做出相应的操作. 我来对比一下truncate table '表明'与drop table '表格名'的区别,跟大家一起学习. drop table '表格名'- ...
- Ubuntu 13.10 64位 无法 安装 ia32-libs 解决办法
安装新立德软件包管理器:打开终端,输入以下命令:sudo apt-get install synaptic 打开新立德软件包管理器,选择“设置>软件库” 选择“其他软件 > 添加” 在AP ...
- delphi 与 C++的基本语法区别
[1]“=”符号 (1)“=”作为比较符.但是,当定义const常量时,“=”又表示赋值符号.而“:=”作为赋值符号. (2)“=”只表示赋值符号 [2]结构体 (1)record 作为结构体 (2) ...
- tmpfs
什么是tmpfs tmpfs是Linux/Unix系统上的一种基于内存的文件系统.tmpfs可以使用您的内存或swap分区来存储文件.由此可见,temfs主要存储暂存的文件. linux内核中的VM子 ...
- awk,perl,python的命令行参数处理
Python,Perl,Bash命令行参数 Part I 日常经常性的和Perl,Python,Bash打交道,但是又经常性的搞混他们之间,在命令行上的特殊性和index的区别,Python真的是人性 ...
- 【转载】perl接受传递参数的方法
#! /usr/bin/perl use Getopt::Std;use warnings;use strict; sub read_from_sh($) { my $file = shift; my ...
- error:could not open D:\java\jre1.8\lib\i386\jvm.cfg
复制一份jre到eclipse的目录下就可以了.
- Java 中日期的几种常见操作 —— 取值、转换、加减、比较
Java 的开发过程中免不了与 Date 类型纠缠,准备总结一下项目经常使用的日期相关操作,JDK 版本 1.7,如果能够帮助大家节约那么几分钟起身活动一下,去泡杯咖啡,便是极好的,嘿嘿.当然,我只提 ...