http://poj.org/problem?id=3067

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 29474   Accepted: 7950

Description

Japan plans to welcome the ACM ICPC World Finals and a lot of roads must be built for the venue. Japan is tall island with N cities on the East coast and M cities on the West coast (M <= 1000, N <= 1000). K superhighways will be build. Cities on each coast are numbered 1, 2, ... from North to South. Each superhighway is straight line and connects city on the East coast with city of the West coast. The funding for the construction is guaranteed by ACM. A major portion of the sum is determined by the number of crossings between superhighways. At most two superhighways cross at one location. Write a program that calculates the number of the crossings between superhighways.

Input

The input file starts with T - the number of test cases. Each test case starts with three numbers – N, M, K. Each of the next K lines contains two numbers – the numbers of cities connected by the superhighway. The first one is the number of the city on the East coast and second one is the number of the city of the West coast.

Output

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

Sample Input

1
3 4 4
1 4
2 3
3 2
3 1

Sample Output

Test case 1: 5

Source

 
 
给坐标排序,求逆序对,手模一下好理解、
 #include <algorithm>
#include <cstring>
#include <cstdio> using namespace std; const int N();
int n,m,k,tr[N];
struct Node
{
int west,east;
}node[N*N];
bool cmp(Node a,Node b)
{
if(a.east==b.east) return a.west>b.west;
return a.east>b.east;
} #define lowbit(x) (x&((~x)+1))
inline void Update(int i,int x)
{
for(;i<=N;i+=lowbit(i)) tr[i]+=x;
}
inline int Query(int x)
{
int ret=;
for(;x;x-=lowbit(x)) ret+=tr[x];
return ret;
} int main()
{
int t; scanf("%d",&t); int h=;
for(long long ans=;h<=t;h++,ans=)
{
scanf("%d%d%d",&n,&m,&k);
for(int i=;i<=k;i++)
scanf("%d%d",&node[i].west,&node[i].east);
sort(node+,node+k+,cmp);
memset(tr,,sizeof(tr));
for(int i=;i<=k;Update(node[i++].west,))
ans+=(long long)Query(node[i].west-);
printf("Test case %d: %I64d\n",h,ans);
}
return ;
}

POJ——T 3067 Japan的更多相关文章

  1. POJ 3067 Japan 【树状数组经典】

    题目链接:POJ 3067 Japan Japan Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 32076   Accep ...

  2. poj 3067 Japan(树状数组求逆序数)

    链接:http://poj.org/problem?id=3067 题意:左边有n个城市,右边有m个城市,建k条道路,问有这k条道路中有多少个交点. 分析:将城市按x和y从小到大排序,对于每条道路,求 ...

  3. POJ 3067 Japan (树状数组求逆序对)

    POJ - 3067 题意:有(1-n)个城市自上到下在左边, 另有(1-m)个城市自上到下在右边,共有m条高速公路,现求这m条直线的交点个数,交点不包括在城市处相交. 题解:先将高速公路读入,然后按 ...

  4. POJ 3067 Japan(树状数组)

                                                                                  Japan   Time Limit: 10 ...

  5. POJ 3067 Japan

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

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

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

  7. 题解报告:poj 3067 Japan(典型BIT)

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

  8. poj 3067 - Japan(树状数组)

    先按第一个数从大到小排序,相等的情况下,第二个数按照从大到小排序..... 预处理后,照着树状数组写就行了... 注意:k的最大值应取1000*1000 代码如下: include <cstdi ...

  9. POJ 3067 Japan(经典树状数组)

    基础一维树状数组  题意:左边一排 1-n 的城市,右边一排 1-m 的城市,都从上到下依次对应.接着给你一些城市对,表示城市这两个城市相连,最后问你一共有多少个交叉,其中处于城市处的交叉不算并且每个 ...

随机推荐

  1. PHP第九课 正則表達式在PHP中的使用

    今天内容 1.正則表達式 2.数学函数 3.日期函数 4.错误处理 正則表達式: 1.模式修正符 2.五个经常使用函数 另外一个正則表達式的站点:http://www.jb51.net/tools/z ...

  2. crazyradio焊接和下载固件过程

    非常早之前买过一套crazyradio的器件和空板.可是一直没有时间焊接出来,前天早上六点起来,安静的弄了一把,识别USB.下载crazyradio固件没问题,记录下过程: 1,首先是焊接,寻常的QF ...

  3. HDU 1114 Piggy-Bank(一维背包)

    题目地址:HDU 1114 把dp[0]初始化为0,其它的初始化为INF.这样就能保证最后的结果一定是满的,即一定是从0慢慢的加上来的. 代码例如以下: #include <algorithm& ...

  4. django 笔记11 装饰器

    在views.py创建 一般用来cookies的装饰器 def auth(func): def inner(request, *args, **kwargs): v = request.COOKIES ...

  5. vuejs on

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. win10 的MQTT + apache-apollo服务器使用

    我的使用环境是windows10 2.下载文件目录(注意:开始看教程说直接打开bin目录下的apollo.cmd文件,闪退,原因是没有java_home环境,必须添加java环境): 3.安装好jav ...

  7. Mojo For Chromium Developers1

    Mojo For Chromium Developers Overview This document contains the minimum amount of information neede ...

  8. caffe(6) Blob,Layer,Net 以及对应配置文件的编写

    深度网络(net)是一个组合模型,它由许多相互连接的层(layers)组合而成.Caffe就是组建深度网络的这样一种工具,它按照一定的策略,一层一层的搭建出自己的模型.它将所有的信息数据定义为blob ...

  9. Kubernetes本地私有仓库配置

    实验环境 master 10.6.191.181 node1 10.6.191.182 node2 10.6.191.183 本地私有仓库 10.6.191.184 一.安装本地私有仓库 1.安装do ...

  10. 如何在Google Play上通过电脑下载apk

    操作步骤: 1.首先打开翻 墙软件. 2.键入网址:http://apps.evozi.com/apk-downloader/ 3.将Google Play里apk的网址,复制到“Package na ...