POJ 3067 Japan 【树状数组经典】

CODESYS连接触摸屏 触摸屏:威纶通-MT8071iP(网络IP:192.168.1.10) 控制器:研华AMAX-5580(PAC)(Win10系统,网络IP:192.168.1.3) CODESYS RTE:RTE 64 V3.5 SP13 Build05 笔记本:Thinkpad L14(网络IP:192.168.1.2) CODESYS IDE:V3.5 SP13(ADD ON V3.5.13.5) 一、确认网络通讯正常(关闭防火墙) 笔记本与触摸屏网络测试情况 笔记本与控制器网络测试情况 二、控制器部分 1、新建 阅读详情

题目链接:POJ 3067 Japan

Japan

Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 32076 Accepted: 8620

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

 
 
题目大意:
西岸有N座城市,东岸有M座城市,两岸之间有K条公路,问公路得总交点数。
大概思路:
假设公路连接的西岸城市为X,东岸城市为Y,则当 X_1 < X_2 && Y_2 < Y_1 时两公路相交.
那么问题到这里就差不多解决啦,先按 X 排一个升序,当 X 相等时 按 Y 排升序。排序完成之后,求 Y 序列的逆序数即为交点总数。
注意事项:
①打代码时一定要心平气和
②树状数组是用来求Y的逆序数的所以范围是Y的范围,注意add()函数的边界
③记得初始化
 
AC code(6656K 500ms):
 1 #include <map>
 2 #include <set>
 3 #include <vector>
 4 #include <cstdio>
 5 #include <cstring>
 6 #include <iostream>
 7 #include <algorithm>
 8 #define ll long long int
 9 #define INF 0x3f3f3f3f
10 using namespace std;
11 
12 const int MAXN = 1002;
13 int N, M, K;
14 int c[MAXN*MAXN];
15 
16 struct node
17 {
18     int x, y;
19 }num[MAXN*MAXN];
20 
21 bool cmp(struct node a, struct node b)
22 {
23     if(a.x == b.x)
24         return a.y <= b.y;
25     return a.x < b.x;
26 }
27 
28 int lowbit(int x)
29 {
30     return x&(-x);
31 }
32 
33 void add(int i, int value)
34 {
35     while(i <= M)
36     {
37         c[i]+=value;
38         i+=lowbit(i);
39     }
40 }
41 
42 ll sum(int i)
43 {
44     ll res = 0;
45     while(i > 0)
46     {
47         res+=(ll)c[i];
48         i-=lowbit(i);
49     }
50     return res;
51 }
52 
53 int main()
54 {
55     int T_case = 0;
56     int t = 0;
57     scanf("%d", &T_case);
58     while(T_case--)
59     {
60         t++;
61         scanf("%d%d%d", &N, &M, &K);
62         memset(c, 0, sizeof(c));
63         for(int i = 1; i <= K; i++)
64         {
65             scanf("%d%d", &num[i].x, &num[i].y);
66         }
67         sort(num+1, num+K+1, cmp);
68         ll ans = 0;
69         for(int i = 1; i <= K; i++)
70         {
71             add(num[i].y, 1);
72             ans+=(i-sum(num[i].y));
73         }
74         printf("Test case %d: %lld\n", t, ans);
75     }
76     return 0;
77 }
View Code

 

Android SDK安装教程(超详细),从零基础入门到精通,从这篇开始_android sdk下载安装 阅读详情

相关推荐

苹果搜索广告ASA开户教程

阅读导航 一、创建账号 1、登录网站 2、填写账号主体信息 3、填写商家和发票信息 4、选择付款方式 二、上传审核材料 1、上传文件 2、请求审批 3、上传文件中的常见问题 一、创建账号 1、用Apple ID登录ASA网站 首先我们进入开户网址:https://app-ads.apple.com/ 如果已拥有Apple ID,直接登录即可,如果没有Apple ID,可以先按照步骤创建Apple ID,再返回登录。 注意,这里登录的Apple ID也有讲究: ① 如果是开发

testflight121的博客 2131

Japan(POJ-3067)

Japan(POJ-3067) 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...

菜鸡的博客 598

eVTOL热管理:从电动车到飞行器的技术跃迁与工程挑战

热管理系统是保障各类电动设备安全、高效运行的核心技术,其基本原理是通过冷却、加热和温度控制,确保电池、电机等关键部件在最佳工况下工作。在新能源汽车领域,热管理技术已相对成熟,但面对eVTOL(电动垂直起降飞行器)这一新兴领域,其设计逻辑需从二维地面转向三维空域,应对环境温度剧烈变化、重量约束极端严苛等全新挑战。eVTOL的热管理不仅是简单的技术移植,更涉及对电池瞬时高功率散热、乘员舱快速温控及多热源耦合等复杂工程问题的系统性解决,直接关系到飞行安全与商业航程。本文聚焦于**环境温度**和**有效载荷**等关

weixin_42521276的博客 615

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

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 (...

weixin_30920597的博客 186

用MATLAB从零实现六足机器人步态仿真:交替三角与波动步态保姆级教程

本文详细介绍了如何使用MATLAB从零实现六足机器人的两种经典步态仿真:交替三角支撑步态和波动步态。通过参数定义、相位设置、运动轨迹生成和三维可视化等步骤,帮助读者掌握六足机器人步态规划的核心技术。教程包含完整代码和详细解析,适合机器人爱好者和相关专业学生学习实践。

weixin_26765363的博客 231

STM32_WS2811驱动

STM32的WS2811驱动

健身房 2842

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

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 &lt;= 1000, N &l...

ling_wang的博客 301

IsaacLab从入门到精通(二) 导入自定义机器人

IsaacLab系列第二讲,导入自定义的机器人及设置

DejaWu33的博客 8469

POJ 3067 Japan(逆序对)

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 <

K键盘里的青春K 735

5G初始注册流程详解(2)-Registration Request

1:了解注册的本质,5G终端为什么要注册? 2:SUCI,SUPI,5G-GUTI的区别? 3:为什么会有COMPLETE REGISTRATION REQUEST呢?

weixin_53220301的博客 3795

生态位宽度计算&可视化展示(R语言)

物种的生态位越宽,该物种的特化程度就越小,倾向于泛化种(generalist species);物种的生态位越窄,倾向于是一个特化种(specialists species)。生态位宽度是指物种(或其它生物单位)在群落中所利用的各种不同资源的总和。本篇所使用为生态位宽度指数即**Levins的生态位宽度指数。

weixin_53705272的博客 4435

3067-Japan(好题)

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 <...

mrgaohaihang的博客 456

Ardupilot无人船(车)mavros自主控制

rover 4.4。

超维空间科技的博客 3231

POJ 3067 Japan(经典树状数组)

基础一维树状数组 题意:左边一排 1-n 的城市,右边一排 1-m 的城市,都从上到下依次对应。接着给你一些城市对,表示城市这两个城市相连,最后问你一共有多少个交叉,其中处于城市处的交叉不算并且每个位置最多只能有有一个交叉。如果左边计数 x1-xn,右边计数 y1-yn,则要出现交叉就是x1与y2相连,y1与x2相连 并(x1-x2)*(y2-y1)<0。所以我们可以首先升序排序x轴,因为城市处不

专注如一的博客 451

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

POJ 3067 Japan (树状数组求逆序数---经典)

Japan Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 27472   Accepted: 7430 Description Japan plans to welcome the ACM ICPC World Finals and a lot of roads

持之以恒 426

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

POJ 3067 Japan 树状数组

题目链接:POJ 3067 Japan Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 27551   Accepted: 7451 Description Japan plans to welcome the ACM ICPC World Final

teddywang 361

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

POJ 3067 Japan【树状数组+逆序对】

传送门:POJ 3067 Japan Time Limit: 1000MS Memory Limit: 65536K Problem Description Japan plans to welcome the ACM ICPC World Finals and a lot of roads must be built for the venue. Japan is tall islan...

Waiting For You 464

POJ 3067 Japan (树状数组)

题目地址:POJ 3067 按x为第一关键字从小到大排序,再按y为第二关键字从小到大排序,然后用y来建立树状数组,每次找比y大的就是每次更新的交点数。 代码如下: #include #include #include #include #include #include #include #include #include using namespace std; #def

scf0920 1514

POJ 3067 Japan【一维树状数组】

POJ 3067 Japan 核心算法:一维树状数组大意:Japan在东边有n座城市,从北到南编号依次为1,2,3...n在西边有m座城市,从北到南编号分别为1,2,3...m现要在南北城市之间修建k条超级高速公路,求会出现多少个十字路口(注:每个十字路口只能由两条交叉的路所构成)输入:T .....cases数 n,m,k 以下k行每行对应于一条高速公路,由两个数字(x...

a48634331的博客 159

poj 3067 树状数组 Japan

题意:http://poj.org/problem?id=3067         两排点,问有多少个焦点。 做题过程:        乍看以为是图论呢,韦广说是树状数组。于是我就开始自己想,自己写。左边那一列点从下往上插(线统计与之相连的那个点之前有的和,再插),与同一点相连的先插下面大的那一点(这样才不会被另外一个点统计)。        哎,刚开始以为在一个位置插了就不能再插了呢,还

Julyana_Lin_夜 650

【树状数组】Japan(POJ3067)PASCAL…

【树状数组】Japan(POJ3067) Time Limit:1000MS  Memory Limit:65536K Total Submit:18 Accepted:10 Description 【问题描述】   日本为了迎接ACM ICPC世界总决赛的到来,计划修建许多道路。日本是一个岛国,其东海岸有N座城市,西海岸有M座城市(M <= 1000, N <= 1000)。K条高速公路将要修

m42ping的专栏 477

poj3067 树状数组解决二维逆序对

一直在学习二维逆序对的解决方法,然后并没有搞明白,这是第一道自己搞出来的模板题。 POJ3067 JAPAN 题解: 设东部的城市为eie_iei​,西部的城市为wiw_iwi​,那么如果连接e1e_1e1​w2w_2w2​和连接e2e_2e2​w1w_1w1​的两条道路想形成交叉,必然有当e1&lt;e2e_1 &lt; e_2e1​<e2​时,w1&gt;w2w_...

__surtr的博客 494

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

POJ 3067 Japan 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

No Rain,No L'Arc~en~Ciel 427

(树状数组)POJ - 3067 Japan

原题链接:http://poj.org/problem?id=3067 题意:左右两条边,分别有n和m 个城市,现在有k条线把左右各一个城市连接起来,问所有的边的交点。 分析:一开始我想用二维树状数组做,就是求在两点交错的边,在二维矩阵中就是找其中一个点去掉右下角子矩阵之外的和,如图,要求的就是粉色部分。 但是因为本身对树状数组还理解还不够透彻,虽然过了样例...

dijieluan7764的博客 151

poj 3067 japan 树状数组

Poj3067 japan 这里求的是高架桥交叉的个数,首先按照规则排序,然后同上处理                这里要注意的是 输入输出要用scanf 且要用sum要用__int64  #include #include #include #define maxn 2005 #define MAX 1000010 using namespace std; struct n

pzz837157806的专栏 1万+

poj3067 Japan(树状数组)

树状数组

1928
上一篇: (第四场)F Beautiful Garden
下一篇: STL - priority_queue(优先队列)
莜莫oO
博客等级 码龄9年 7粉丝 226原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值