地址: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. Android Intent 用法全面总结(转载)

    1. [代码]调用拨号程序 1 2 3 4 // 给移动客服10086拨打电话 Uri uri = Uri.parse("tel:10086"); Intent intent = ...

  2. 第二百四十一节,Bootstrap进度条媒体对象和 Well 组件

    第二百四十一节,Bootstrap进度条媒体对象和 Well 组件 学习要点: 1.Well 组件 2.进度条组件 3.媒体对象组件 本节课我们主要学习一下 Bootstrap 的三个组件功能:Wel ...

  3. 【BZOJ】3203: [Sdoi2013]保护出题人(几何+三分+特殊的技巧)

    http://www.lydsy.com/JudgeOnline/problem.php?id=3203 wa无数次QAQ,犯sb错....一是数组没有引用...二是输出转成了int(越界了sad). ...

  4. 【BZOJ】3392: [Usaco2005 Feb]Part Acquisition 交易(spfa)

    http://www.lydsy.com/JudgeOnline/problem.php?id=3392 同1674 #include <cstdio> #include <cstr ...

  5. 华为OJ平台试题 —— 数组:输入n个整数,输出当中最小的k个

    输入n个整数.输出当中最小的k个: 代码: /*  * 输入n个整数,输出当中最小的k个.  * 输入说明:1.输入两个整数:2.输入一个整数数组  * 输出说明:输出一个整数数组  */ <p ...

  6. js json 单双引号互换

    var _adrobj = JSON.stringify(address).replace(/\"/g,"'"); var _nstr = _adrdata.replac ...

  7. python3----练习题(冒泡排序)

    冒泡,原理是临近的数字两两进行比较,按照从小到大的顺序进行交换,这样交换一次之后,最大的数字就被交换到了最后一位. li = [33, 2, 10, 1] for j in range(1, len( ...

  8. android 性能測试CTS篇

    CTS介绍 一.CTS简单介绍 CTS 全称Compatibility Test Suite兼容性測试工具. 当电子产品开发出来.并定制了自己的Android系统后,必需要通过最新的CTS检測.以保证 ...

  9. IOS学习笔记28—SQLite3第三方库之FMDB

    本文转载至 http://blog.csdn.net/happyrabbit456/article/details/11609451 SQLite是一种小型的轻量级的关系型数据库,在移动设备上使用是非 ...

  10. hdu1814(2-SAT)

    2-SAT 求出可能的解,但是这个解要是字典序最小的,所以只能采用2-SAT基本思想来解. 从小到大开始,对一个可能的点染色,染为1,然后dfs其所有能到达的点,如果其中出现一个已经标号为-1的话,那 ...