Japan POJ3067
Japan POJ3067
题目:有2个竖下来的点,给出许多连线,问有多少交叉,
思路:连线按左端点a从小到大排序,每次都查询右端点b的后缀和即可(画个图理解)
代码:
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
const int maxn= 1e3+5;
int c[maxn];
struct node
{int a,b;
}no[1000*1000+5];
int lowbit(int x) //算最低位1的值
{return x&-x;
}
void update(int k,int a,int b[]) //更新树状数组c[k]
{for(;k<=maxn;b[k]+=a,k+=lowbit(k));
}
int sum(int k,int b[]) //一维计算1-k
{int res=0;for(;k>0;res+=b[k],k-=lowbit(k));return res;
}
bool comp(node a,node b)
{
if(a.a==b.a)return a.b<=b.b;else return a.a<b.a;
}
int main()
{int t,n,m,k;cin>>t;for(int t1=1;t1<=t;t1++){long long ans=0;memset(c,0,sizeof(c));cin>>n>>m>>k;for(int i=1;i<=k;i++){scanf("%d%d",&no[i].a,&no[i].b);}sort(no+1,no+1+k,comp);for(int i=1;i<=k;i++){update(no[i].b,1,c);ans+=sum(m,c)-sum(no[i].b,c); //b后面的数量,画个图就知道了 }printf("Test case %d: %lld\n",t1,ans);}return 0;
}
Japan POJ3067相关推荐
- POJ-3067 Japan(树状数组、线段树)
题目链接 Description Japan plans to welcome the ACM ICPC World Finals and a lot of roads must be built f ...
- POJ3067 Japan(归并排序)
题意: 日本西海岸有n座城市,东海岸m座城市.现在要在两个海岸的城市之间建高速公路,问有几个相交点. 要点: 对Ax,Ay和Bx,By两条高速公路,有相交点必须(Ax-Bx)*(Ay-By)<0 ...
- POJ3067 Japan
题目链接:http://poj.org/problem?id=3067 求交叉数,先按第一列排序,再对第二列求逆序对 注意会爆int 注意==和=,一不留神写错还没看出来 贴代码 #include&l ...
- 参加LinuxCon Japan 2012
好长时间没有写博客了.一是时间紧张,另外是这段时间来没有什么可记录的,也发现越来越没有什么文笔可言了,越来越趋于流水账形式了. 发现上小学的时候一写流水账就会被老师批评,说这孩子作文写的跟记流水账似的 ...
- POJ-3067 Japan---树状数组逆序对变形
题目链接: https://vjudge.net/problem/POJ-3067 题目大意: 日本岛东海岸与西海岸分别有N和M个城市,现在修高速公路连接东西海岸的城市,求交点个数. 解题思路: 记每 ...
- Dummies Guide to Trains in Japan
来源:http://www.goaround.org/travel-asia/247702.htm Q:I've traveled to Europe (London's Tube, Paris' M ...
- First of all, let’s talk about the richest man in Japan
First of all, let's talk about the richest man in Japan! Japan's most famous rich are Masaru Yanai a ...
- 每日英语:Japan Leader Warns China on Islands Dispute
TOKYO-Japan's prime minister warned China that its inflammatory reaction to a territorial dispute-fr ...
- 「YGG Japan」宣布已完成约 295 万美元的新股权私募
ForN(总部位于东京都港区:CEO 藤原哲哉:以下简称 "ForN" )今天宣布,与 ForN 合作的区块链游戏平台 YGG Japan 已完成价值约 295 万美元的私募轮融资 ...
最新文章
- Solution 24: 链表翻转
- QT 5.4.1 for Android Ubuntu QtWebView Demo
- 测量仪图片_南昌高度仪价格,大行程非标影像测量仪组装
- 【C++grammar】结构化绑定
- php css布局技巧,最全的CSS开发常用技巧
- 男生给女生最牛B的告白
- c 如何操作php,thinkphp的c方法使用示例
- CentOS7.2安装jdk7u80
- -矩阵-创建矩阵-meshgrid函数
- qgraphicsview鼠标移动图片_交互式QGraphicsView(平移/缩放/旋转)-阿里云开发者社区...
- C语言复习---输出魔方阵
- 64位java_java64位
- 斐讯K1K2刷机固件教程!最新最全整理版!(小米路由、newifi通用)
- 【用行动说话】第一篇博客
- 微博 php7,PHP_迁移PHP版本到PHP7,今天看到微博上说phpng也就是ph - phpStudy
- redis搭建哨兵模式(哨兵模式原理)
- 新番 | 万万没想到,Hulu有一天也开始推新番了
- MySQL字段约束及多表查询---讲解三
- 隐藏的Word快捷键操作
- 蚂蚁金服、滴滴们掀起A/H上市潮,它们能打破折溢价的烦恼吗?