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. OpenCASCADE License FAQs

    OpenCASCADE License FAQs 经常用人问我使用OpenCASCADE开发商业软件是否需要付费,下面从OpenCASCADE的官方网站上截取其回答翻译成中文,官方网址:https:/ ...

  2. 【C#】报表制作&lt;机房重构&gt;

    前言 和VB须要引用其它报表软件不同,VS自带报表设计的功能,初次尝试.就感受到了它的强大之处. 报表制作 话不多说.直接报表的制作过程. 1.首先,我们要先制作一个报表的容器.放到我们显示报表的窗口 ...

  3. 13.mutiset树每一个结点都是一个链表的指针,可以存储相同的数据

    #include <iostream> //红黑树(自动保证平衡,自动生成平衡查找树) #include <set> #include <cstring> #inc ...

  4. Tomcat vs. Jetty vs. Undertow: Comparison of Spring Boot Embedded Servlet Containers

    原文地址:https://examples.javacodegeeks.com/enterprise-java/spring/tomcat-vs-jetty-vs-undertow-compariso ...

  5. OpenGL编程逐步深入(七)旋转变换

    准备知识 这一节我们来看一下旋转变换.旋转变换指的是给我们一个指点的点和角度,我们需要绕着过该点的轴线將对象旋转对应的角度.这里我们只改变X/Y/Z中的两个分量,第三个分量保持不变.这意味着我们的图形 ...

  6. ArchLinux 调节屏幕亮度和音量大小

    我使用的是dwm,所以这种琐碎小事还要我们亲自动手, 以后考虑做个脚本,把声音调节.屏幕亮度什么的统统塞进去 屏幕亮度 # 查看亮度最大值 cat /sys/class/backlight/intel ...

  7. RC Immix

    目录 RC Immix 目的 合并型引用计数 伪代码 优点和缺点 合并型引用计数法和Immix的融合 新对象 被动的碎片整理 积极的碎片整理 优点和缺点 优点 缺点 RC Immix Rifat Sh ...

  8. nginx配置aliyun https

    server { listen 443; server_name www.goforit.com goforit.com; ssl on; ssl_certificate cert/goforit.p ...

  9. TI C66x DSP 四种内存保护问题 -之- 外设訪问corePac内部资源时的内存保护问题

    外设訪问corePac内部资源(L1,L2)时的内存保护等问题请參考以下两个blog.已经叙述的非常具体. "TI C66x DSP 系统events及其应用 - 2"," ...

  10. STL 之 hash_map源代码剖析

    // Filename: stl_hash_map.h // hash_map和hash_multimap是对hashtable的简单包装, 非常easy理解 /* * Copyright (c) 1 ...