poj 3067

树状数组求逆序数的应用:

 

Japan
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 17874 Accepted: 4819

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
题意很好理解,就是对v进行降序排列,然后求逆序数的个数就是交点的个数:
代码如下:

#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include<map>
#include<ctype.h>
#define ll long long
#define loop1(k) for(int i=1;i<=k;i++)
#define loop2(k) for(int j=1;j<=k;j++)
#define pr(i) printf("%d\n",i);
using namespace std;
int n,m,k;
struct node{
int a;
int b;
}edge[1001000];
int cc[1001000];
bool cmp(node c,node d ){
if(c.a==d.a)
return c.b<d.b;
return c.a<d.a;
}
int low(int x){
return x&(-1*x);
}
int sum(int x){
int num=0;
while(x>=1){
num+=cc[x];
x-=low(x);
}
return num;
}
void update(int x)
{
while(x<=m)
{
cc[x]++;
x+=low(x);
}
}
int main()
{
int t;
scanf("%d",&t);
int ci=1;
while(t--){
memset(cc,0,sizeof(int)*m+15);
scanf("%d%d%d",&n,&m,&k);
memset(cc,0,sizeof(int)*m+15);
for(int i=1;i<=k;i++)
scanf("%d%d",&edge[i].a,&edge[i].b);
sort(edge+1,edge+1+k,cmp);
__int64 ans = 0;
for(int i=1;i<=k;i++){
update(edge[i].b);
ans+=sum(m)-sum(edge[i].b);
}
printf("Test case %d: %I64d\n", ci, ans);
ci++;
}
return 0;
}

 

转载于:https://www.cnblogs.com/keephungry/p/3330441.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/547363.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

取消计算机触摸板,笔记本电脑触摸板,详细教您笔记本电脑触摸板怎么关闭

很多的笔记本的用户都习惯使用鼠标&#xff0c;主要是因为笔记本触摸板操作不太方便&#xff0c;没有鼠标操作灵活。反而是经常在电脑中打字等操作时容易误碰到笔记本触摸板&#xff0c;导致输入错误等等&#xff0c;因此很多朋友一般会关闭触摸板&#xff0c;可是笔记本触摸板…

OC学习笔记--基础篇

本文简要介绍了一些oc的基础类型&#xff0c;包括数组、字典、字符串、消息传递、类、对象、方法、属性、协议和转发&#xff0c;希望对你有帮助。 OC数据类型 打印—类似print NSlog("hello word");数组 NSMutableArray &#xff08;可变数组&#xff09;和 NSAr…

linux gcc编译下的文件读写操作

linux下的文件操作 所有目录 1.文件及文件系统的定义 2.linux文件的类型 3.linux文件的权限 4.文件操作 4.1 文件的创建 4.2 文件的打开及关闭 4.3 文件的读写操…

PL/SQL Developer中文版下载以及使用图解(绿色版)

下载地址&#xff1a;http://pan.baidu.com/s/1eQCTmkM 1、运行plsqldev.exe程序&#xff1b; 2、设置Oracle主目录名/OCI库地址&#xff0c;如图&#xff1a; 重新启动程序。 3、配置登陆信息&#xff0c;连接数据库&#xff0c;如图&#xff1a;

实例应用 自定义页面taglib标签

关于继承TagSupport与BodyTagSupport的区别说明 * <code>TagSupport</code>与<code>BodyTagSupport</code>的区别主要是标签处理类是否需要与标签体交互。 * 如果不需要交互的就用<code>TagSupport</code>&#xff0c;如果需要交互就用<…

魔兽世界怀旧服聊天服务器中断,魔兽世界怀旧服世界服务器无法连接

本文导航第1页&#xff1a; 服务器无法连接解决方法服务器无法连接解决方法今天是魔兽世界怀旧服的公测时间&#xff0c;服务器已经爆了&#xff0c;很多玩家都在反应游戏服务器进不去&#xff0c;或者服务器断开连接等等问题&#xff0c;针对这些情况&#xff0c;小编特意给大…

Express框架使用以及数据库公共操作类整理(Win7下的NodeJs)

具体步骤&#xff1a; 1、安装开发工具WebStorm&#xff1b; 2、安装node/npm&#xff08;下载地址&#xff1a;https://nodejs.org/download/&#xff09;选择适合你的xxx.mis安装&#xff1b; 3、安装express框架(cmd窗口模式&#xff0c;用npm命令执行&#xff1a;npm in…

SimpleITK使用深度学习识别肺癌CT DICOM数据集

肺癌数据集DICOM &#xff1a;https://wiki.cancerimagingarchive.net/display/Public/LIDC-IDRI 首先用SimpleITK把mhd图片读入&#xff0c;对每个切片使用Gaussian filter然后使用阈值-600把肺部图片二值化&#xff0c;然后再分析该切片的面积&#xff0c;去掉面积小于30mm2的…

两个文件夹数据同步

echooffechoechoAuthorlongwenby2013echo每天下午16&#xff1a;00和晚上22&#xff1a;00做自动更新echo时间由您的计划任务时间确定echoRelationlongwen260qq.comechoQQ476376997echoTel13480986813echoxcopyD:\svn\te\*.*E:\svn\te\*.*/s/e/m/y转载于:https://blog.51cto.co…

如何让nodejs同步操作

众所周知&#xff0c;异步是nodejs中得天独厚的特点和优势&#xff0c;但同时在程序中同步的需求&#xff08;比如控制程序的执行顺序为&#xff1a;func1 -> func2 ->func3 &#xff09;也是很常见的。本文就是对这个问题记录自己的一些想法。 需要执行的函数&#xff…

Mediapipe框架学习之一——Win10安装Mediapipe环境

Mediapipe官方文档 Mediapipe框架学习之一——Win10安装Mediapipe环境 Mediapipe框架学习之二——Android SDK and NDK 配置 Mediapipe框架学习之三——构建 MediaPipe 的 Android aar 包 Mediapipe框架学习之四——利用 Mediapipe aar 包&#xff0c;在AS中构建基于 Media…

MemCache在win7上的可视化配置以及Nodejs/Net应用

惯例科普&#xff1a;MemCache是一套分布式的高速缓存系统&#xff0c;由LiveJournal的Brad Fitzpatrick开发&#xff0c;但目前被许多网站使用以提升网站的访问速度&#xff0c;尤其对于一些大型的、需要频繁访问数据库的网站访问速度提升效果十分显著。这是一套开放源代码软件…

Android AM命令行启动程序的方法

http://blog.csdn.net/sunrock/article/details/5675067 在前面添加一句 启动服务的话 使用 am startservice com.lxb.window/.RecordService即可在Android中&#xff0c;除了从界面上启动程序之外&#xff0c;还可以从命令行启动程序&#xff0c;使用的是命令行工具am.usage: …

Apache httpd 配置HTTPS SSL访问 443

2, 首先安装https模块yum install mod_ssl 3. 配置Apache Web服务器 首先&#xff0c;修改下面的配置文件。仅需配置红色部分 SSLCertificateFile 和 SSLCertificateKeyFile # vim /etc/httpd/conf.d/ssl.conf # # When we also provide SSL we have to listen to the # t…

Redis在win7上的可视化应用

Redis是一个key-value存储系统。和Memcached类似&#xff0c;它支持存储的value类型相对更多&#xff0c;包括string(字符串)、list(链表)、set(集合)、zset(sorted set --有序集合)和hash&#xff08;哈希类型&#xff09;。这些数据类型都支持push/pop、add/remove及取交集并…

全网最详细的docker配置nginx http2 优化高速访问

Nginx 从 1.13.9 版本开始加入了 HTTP/2 的 Server Push 功能&#xff0c;本文将介绍如何在 Nginx 下实现 HTTP/2 服务器推送 (Server Push) 。这里我们首先用 Docker 搭建一个支持 HTTP/2 的 Server Push 功能的 Nginx 容器并加入 SSL 证书。如果你还不会 Docker&#xff0c;可…

Flex Graphics

<?xml version"1.0" encoding"utf-8"?> <s:Application xmlns:fx"http://ns.adobe.com/mxml/2009" xmlns:s"library://ns.adobe.com/flex/spark" xmlns:mx"library://ns.adobe.com/flex/halo"minWidth"1024…

CentOS安装运行NodeJS框架Express

安装依赖包 yum -y install gcc make gcc-c openssl-devel wget 下载/解压NodeJs wget http://nodejs.org/dist/v0.12.7/node-v0.12.7.tar.gztar -zvxf node-v0.12.7.tar.gz 编译及安装&#xff0c;逐行执行 cd node-v0.12.7./configuremake install 验证是否安装配置成功&…

android点滴27:R文件无法加载 R cannot be resolved to a v...

2019独角兽企业重金招聘Python工程师标准>>> 导致这个问题原因可能有二个&#xff1a;1. manifest文件中的包名和真正的报名不统一 2. 在java文件中导入了R文件&#xff0c;在java文件中无需导入任何包的R文件&#xff0c;系统会自动加载gen目录下的R文件。 转载于…

MITK医学Python开发入门详细版

1.关于MITK&#xff1a; MITK的全称是”The Medical Imaging Interaction Toolkit”。它是一款开源的交互式医学图像处理软件开发和应用平台。MITK将ITK和VTK整合为一个应用框架。该软件由德国一个研究室开发。官网地址为&#xff1a;http://mitk.org/wiki/MITK 。 与MITK同名…