poj-3067-japan--(树状数组)
来源:互联网 发布:淘宝大学的vip课靠谱吗 编辑:程序博客网 时间:2024/06/08 18:53
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)
Test case (case number): (number of crossings)
Sample Input
13 4 41 42 33 23 1
Sample Output
Test case 1: 5
用树状数组求逆序数
代码:
#include<iostream>#include<string>#include<cstdio>#include<algorithm>#include<cmath>#include<iomanip>#include<queue>#include<cstring>#include<map>using namespace std;typedef long long ll;#define pi acos(-1.0)#define inf 0x3f3f3f#define M 1001000int n,m,k,tree[1005];struct node{ int s,e; bool operator < (const node &a) const { return e<a.e||(e==a.e&&s<a.s); }}p[M];int lowbit(int i){ return i&(-i);}void add(int i,int v){ while(i<=n) { tree[i]+=v; i+=lowbit(i); }}ll sum(int i){ ll res=0; while(i>0) { res+=tree[i]; i-=lowbit(i); } return res;}int main(){ int T,i,cas=0; scanf("%d",&T); while(T--) { scanf("%d%d%d",&n,&m,&k); for(i=1;i<=k;i++) scanf("%d%d",&p[i].s,&p[i].e); sort(p+1,p+k+1); memset(tree,0,sizeof(tree)); ll cnt=0; for(i=1;i<=k;i++) { cnt+=sum(n)-sum(p[i].s); add(p[i].s,1); } printf("Test case %d: %I64d\n",++cas,cnt); } return 0;}
阅读全文
1 0
- POJ 3067 Japan【树状数组】
- poj 3067 japan 树状数组
- poj 3067 树状数组 Japan
- POJ 3067 Japan 树状数组
- POJ 3067 Japan 树状数组
- poj 3067 - Japan(树状数组)
- 树状数组 - POJ 3067 Japan
- Poj 3067 Japan 树状数组
- Poj 3067 Japan【树状数组】
- POJ 3067Japan 树状数组
- POJ 3067 Japan(树状数组)
- POJ 3067 Japan 树状数组
- POJ 3067 Japan 树状数组 .
- POJ 3067 Japan 树状数组
- poj 3067 Japan(树状数组)
- poj-3067-japan--(树状数组)
- POJ 3067 Japan 二维树状数组
- poj 3067 Japan(线段树 | 树状数组)
- krpano 安装 新手教程
- Supermarket POJ
- 在Ecplise里面导入Myecplise Web工程
- QTableWidget单元格自动分行显示
- JQuery 导航
- poj-3067-japan--(树状数组)
- 51nod 1799 二分答案 思维 + 分块打表
- css3弹性盒及其属性和视口的介绍
- JQuery效果
- 线程同步--synchronized详解
- Comparator和Comparable和类Collator的区别?(对象排序)
- Selenium实例1-自动登录小米社区并获取主题帖
- ubuntu下安装selenium以及chromedriver、geckodriver和phantomjs等驱动
- codevs 玛丽卡(最短路路径记录)