cdojR - Japan
地址:http://acm.uestc.edu.cn/#/contest/show/95
题目:
R - Japan
Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others)
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 |
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的更多相关文章
- POJ 3067 Japan(树状数组)
Japan Time Limit: 10 ...
- Japan
Japan plans to welcome the ACM ICPC World Finals and a lot of roads must be built for the venue. Jap ...
- POJ 3067 Japan
Japan Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 25489 Accepted: 6907 Descriptio ...
- cdoj 383 japan 树状数组
Japan Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/383 Descrip ...
- 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 ...
- 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 ...
- POJ 3067 - Japan - [归并排序/树状数组(BIT)求逆序对]
Time Limit: 1000MS Memory Limit: 65536K Description Japan plans to welcome the ACM ICPC World Finals ...
- poj3067 Japan(树状数组)
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:id=3067">http://poj.org/problem? id=3067 Descri ...
- Japan POJ - 3067 转化思维 转化为求逆序对
Japan plans to welcome the ACM ICPC World Finals and a lot of roads must be built for the venue. Jap ...
随机推荐
- 【转】【CTO俱乐部走进支付宝】探索支付宝背后的那些技术 部分
怎么避免研发环节当中引入漏洞?“我们有一套比较成熟的安全研发开发框架.首先我们用统一的框架,框架本身是经过我们安全工程师去做过非常好的认证的,同时在研发过程当中我们对这些问题也有些规范.一旦发现风险我 ...
- php视频教程
网址:http://www.php100.com/index.html
- yalmip + lpsolve + matlab 求解混合整数线性规划问题(MIP/MILP)
最近建立了一个网络流模型,是一个混合整数线性规划问题(模型中既有连续变量,又有整型变量).当要求解此模型的时候,发现matlab优化工具箱竟没有自带的可以求解这类问题的算法(只有bintprog求解器 ...
- MS SqlServer 2008R2- Sql语句循环遍历生成百条随机数
Sql语句,循环遍历生成区间5~20的随机数语句如下: are @i int DECLARE @Result INT DECLARE @Upper INT DECLARE @Lower INT ) ) ...
- npm中本地安装命令行类型的模块是不注册Path的
http://www.jianshu.com/p/c04dea6e46de 首先有必要解释下什么是命令行(Command Line)类型的模块.npm的模块一共分为三类: 绑定型(Binding):本 ...
- python3----生成器generator(yield)
# 列表推导式a = [i for i in range(100) if not(i % 2) and (i % 3)]print(a)# 字典推导式b = {i: i % 2 == 0 for i ...
- 编写高质量代码--改善python程序的建议(三)
原文发表在我的博客主页,转载请注明出处! 建议十三:警惕eval()的安全漏洞 相信经常处理文本数据的同学对eval()一定是欲罢不能,他的使用非常简单: eval("1+1==2" ...
- iOS 导航栏rgb值与设置的有差异
转:http://b2cloud.com.au/how-to-guides/bar-color-calculator-for-ios7-and-ios8/ 计算:http://htmlpreview. ...
- xmpp muc 群聊协议 3
6. Entity Use Cases A MUC implementation MUST support Service Discovery [7]. 服务端必须实现 service discove ...
- Java 8 Lambda 表达式详解
一.Java 8 Lambda 表达式了解 参考:Java 8 Lambda 表达式 | 菜鸟教程 1.1 介绍: Lambda 表达式,也可称为闭包,是推动 Java 8 发布的最重要新特性. La ...