poj japan 数状数组解决逆序数
这道提树状数组球逆序数 关键在于 问有多少哥焦点 即使焦点在同一个位置
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
using namespace std;
struct node
{int x;int y;
}a[1000005];
int c[1005];
int max1;
bool cmp(node a,node b){return (a.x<b.x)||(a.x==b.x&&a.y<b.y);//判断 当一个点想多向点链接的时候 不算焦点
}
int lowbit(int x){return x&(-x);
}
void insert(int x,int y){while(x<=max1){c[x]+=y;x=x+lowbit(x);}
}
long long sum(int x){int t=0;while(x>=1){t+=c[x];x=x-lowbit(x);}return t;
}
int main()
{int te,m,n,k;int kk=1;scanf("%d",&te);while(te--){scanf("%d%d%d",&n,&m,&k);max1=0;for(int i=0;i<=1002;i++) c[i]=0;for(int i=1;i<=k;i++){scanf("%d%d",&a[i].x,&a[i].y);if(a[i].y>max1)max1=a[i].y;}sort(a+1,a+k+1,cmp);long long ans=0;for(int i=1;i<=k;i++){ans+=(sum(max1)-sum(a[i].y));insert(a[i].y,1);}printf("Test case %d: %lld\n",kk++,ans);}return 0;
}
poj japan 数状数组解决逆序数相关推荐
- Japan树状数组求逆序数
http://poj.org/problem?id=3067 给出一个序列 a1 a2 a3 ···an 问此序列中逆序对的个数? 逆序对:i<j,ai>aj 方法:就是用树状数组搞,从后 ...
- 离散化+树状数组求逆序数
题目:http://poj.org/problem?id=2299 离散化是一种常用的技巧,有时数据范围太大,可以用来放缩到我们能处理的范围 因为其中需排序的数的范围0--- 999999999:显然 ...
- poj 2299 Ultra-QuickSort(树状数组求逆序数+离散化)
题目链接:http://poj.org/problem?id=2299 Description In this problem, you have to analyze a particular so ...
- hdu 1394(树状数组求逆序数)
解题思路:这道题是求循环数组中逆序数最小值,求逆序数这里肯定是用树状数组.只是这里有一点点变化,由于题目中n位数是0-n-1的一个排列,所以num[i]可表示为比num[i]小的数的个数.把第一位的数 ...
- HDU 2838 Cow Sorting(双树状数组+求逆序数)
Problem Description Sherlock's N (1 ≤ N ≤ 100,000) cows are lined up to be milked in the evening. Ea ...
- 归并排序树状数组求逆序数
归并排序: #include <iostream> #include <vector> using namespace std; vector<int>input, ...
- HDU 4911 Inversion 树状数组求逆序数对
显然每次交换都能降低1 所以求出逆序数对数,然后-=k就好了.. . _(:зゝ∠)_ #include<stdio.h> #include<string.h> #includ ...
- Swaps and Inversions hdu多校训练第二场 树状数组求逆序数+离散化
http://acm.hdu.edu.cn/showproblem.php?pid=6318 交换相邻的元素,有几个逆序对,就交换几次使其变成顺序对 #include<bits/stdc++.h ...
- 用树状数组解决求区间最值的问题:hdu1754
以前都学过树状数组,但是已经差不多忘记了!不过看一看后,马上就都回忆起来了!而且感觉经过这么久的学习,对树状数组有了更深一层的领悟!个人觉得树状数组在本质上与线段树是没有区别的!都是管理区间,只不过树 ...
- 树桩数组求逆序数+离散化(数太大)
http://acm.hdu.edu.cn/showproblem.php?pid=3743 求a1 a2 a3 ...an此序列的逆序数 怎么离散化? 首先将序列由小到大排序, 用排序后该数的位置代 ...
最新文章
- mariadb galera Cluster 多主集群安装实录
- 攻击链路识别——CAPEC(共享攻击模式的公共标准)、MAEC(恶意软件行为特征)和ATTCK(APT攻击链路上的子场景非常细)...
- MQTT 5.0 新特性(三)| 有效载荷标识与内容类型
- 云计算的8个常见用途
- nyoj543遥控器
- SQL SERVER作业的Schedules浅析
- 最好用的手机端C/C++语言编程软件, 不要说没电脑就不学编程了!
- AIX7.1环境打补丁缺少bash OPATCHAUTO-72049
- Mac基础操作:如何用启动台来查看和打开App
- VB.net 进度条使用
- 【读书笔记】商业自传-PayPal程序员-硅谷钢铁侠-埃隆·马斯克,SpaceX CEO、特斯拉公司CEO、太阳城公司董事会主席。
- uipath 验证码_UiPath邮件自动化Save Attachments的介绍和使用
- Mysql如何按照指定间隔时间查询数据
- iOS AirPlay 投屏调研
- void* LPVOID是些什么东东
- php在线拍照裁切,基于cropper.js封装vue实现在线图片裁剪组件的功能
- 手机android系统安装,如何重新安装Android手机系统
- 计算机鼠标装有,计算机插入鼠标时无法安装设备驱动程序的解决方法
- 重绘回流个人理解版本
- mysql order by file_深聊MySQL,从入门到入坟之:如何让order by、group by查询速度飞起来...