地址:http://acm.uestc.edu.cn/#/contest/show/95

题目:

R - Japan

Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others)
Submit Status
N

Input

T

Output

For each test case write one line on the standard output: Test case (case number): (number of crossings)

Sample input and output

Sample Input Sample Output
1
3 4 4
1 4
2 3
3 2
3 1
Test case 1: 5

Hint

The data used in this problem is unofficial data prepared by pfctgeorge. So any mistake here does not imply mistake in the offcial judge data.

思路:

又是逆序对,具体的不多说了,和前面的某题一样,,,

归并求逆序对数,,

 #include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cstdlib>
#include <string> #define PI acos((double)-1)
#define E exp(double(1))
using namespace std; vector<pair<long long,long long > >p;
long long a[+];
long long temp[+];
long long cnt=;//逆序对的个数
void merge(int left,int mid,int right)
{
int i=left,j=mid+,k=;
while (( i<=mid )&& (j<=right))
if (a[i]<=a[j]) temp[k++]=a[i++];
else
{
cnt+=mid+-i;//关键步骤
temp[k++]=a[j++];
}
while (i<=mid) temp[k++]=a[i++];
while (j<=right) temp[k++]=a[j++];
for (i=,k=left; k<=right;) a[k++]=temp[i++];
}
void mergeSort(int left,int right)
{
if (left<right)
{
int mid=(left+right)/;
mergeSort(left, mid);
mergeSort(mid+, right);
merge(left, mid, right);
}
}
int main (void)
{
int n,u,v,t;
cin>>t;
for(int i=;i<=t;i++)
{
p.clear();
cnt=;
cin>>u>>v>>n;
for(int i=; i<n; i++)
{
long long k,b;
scanf("%lld%lld",&k,&b);
p.push_back(make_pair(k,b));
}
sort(p.begin(),p.end());
for(int i=; i<n; i++)
a[i]=p[i].second;
mergeSort(,n-);
printf("Test case %d: %lld\n",i,cnt);
}
return ;
}

cdojR - Japan的更多相关文章

  1. POJ 3067 Japan(树状数组)

                                                                                  Japan   Time Limit: 10 ...

  2. Japan

    Japan plans to welcome the ACM ICPC World Finals and a lot of roads must be built for the venue. Jap ...

  3. POJ 3067 Japan

    Japan Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 25489   Accepted: 6907 Descriptio ...

  4. cdoj 383 japan 树状数组

    Japan Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/383 Descrip ...

  5. Day 3 @ RSA Conference Asia Pacific & Japan 2016 (morning)

    09.00 – 09.45 hrs Tracks Cloud, Mobile, & IoT Security    A New Security Paradigm for IoT (Inter ...

  6. Day 4 @ RSA Conference Asia Pacific & Japan 2016

    09.00 – 09.45 hrs Advanced Malware and the Cloud: The New Concept of 'Attack Fan-out' Krishna Naraya ...

  7. POJ 3067 - Japan - [归并排序/树状数组(BIT)求逆序对]

    Time Limit: 1000MS Memory Limit: 65536K Description Japan plans to welcome the ACM ICPC World Finals ...

  8. poj3067 Japan(树状数组)

    转载请注明出处:http://blog.csdn.net/u012860063 题目链接:id=3067">http://poj.org/problem? id=3067 Descri ...

  9. Japan POJ - 3067 转化思维 转化为求逆序对

    Japan plans to welcome the ACM ICPC World Finals and a lot of roads must be built for the venue. Jap ...

随机推荐

  1. 谈谈对XML的理解?说明Web应用中Web.xml文件的作用?

    谈谈对XML的理解?说明Web应用中Web.xml文件的作用? 解答:XML(Extensible Markup Language)即可扩展标记语言,它与HTML一样,都是SGML(Standard ...

  2. js Date操作

    new Date(new Date().getTime() - 24 * 24 * 60 * 60 * 1000)类似C#中的AddDays,返回一个月前的时间  //时间格式化方法        v ...

  3. Pat(Advanced Level)Practice--1026(Table Tennis)

    Pat1026代码 题目描写叙述: A table tennis club has N tables available to the public. The tables are numbered ...

  4. db2 常用类型

    DB2的常用数据类型包括以下几个: 一.数字型的. 1. SMALLINT          ---短整型,范围为-32768~+32767,一遍用的较少 2. INT/INTEGER    ---整 ...

  5. hdu 4067(最小费用最大流)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4067 思路:很神奇的建图,参考大牛的: 如果人为添加t->s的边,那么图中所有顶点要满足的条件都 ...

  6. npm中本地安装命令行类型的模块是不注册Path的

    http://www.jianshu.com/p/c04dea6e46de 首先有必要解释下什么是命令行(Command Line)类型的模块.npm的模块一共分为三类: 绑定型(Binding):本 ...

  7. Python实现生命游戏

    1. 生命游戏是什么 生命游戏是英国数学家约翰·何顿·康威在1970年发明的细胞自动机.它包括一个二维矩形世界,这个世界中的每个方格居住着一个活着的或死了的细胞.一个细胞在下一个时刻生死取决于相邻八个 ...

  8. jQuery中如何给动态添加的元素绑定事件

    jquery中绑定事件一般使用bind,或者click,但是这只能是对已经加载好的元素定义事件,那些后来添加插入的元素则需要另行绑定.在1.7版本以前使用live.但是在1.8版本以后推荐使用on.这 ...

  9. Ubuntu右键添加:open in terminal

    1.安装软件nautilus-open-terminal sudo apt-get install nautilus-open-terminal 2.重新加载文件管理器 nautilus -q 重新打 ...

  10. PIP源使用国内镜像

    对于Python开发用户来讲,PIP安装软件包是家常便饭.但国外的源下载速度实在太慢,浪费时间.而且经常出现下载后安装出错问题.所以把PIP安装源替换成国内镜像,可以大幅提升下载速度,还可以提高安装成 ...