51nod1107(斜率小于0的连线个数)
来源:互联网 发布:网络打鱼软件 编辑:程序博客网 时间:2024/06/06 06:32
题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1107
先分别以 x 和 y 为第一和第二关键字从小到大排序,然后对 y 求逆序对……
一开始竟然想用线段树来做……
#include <iostream>#include <cstdio>#include <algorithm>using namespace std;typedef long long LL;const LL maxn = 50000 + 10;struct Point{ LL x, y; Point() {} Point(LL x, LL y):x(x), y(y) {}}P[maxn];LL a[maxn];LL r[maxn];LL n;LL ans;int cmp(const Point& a, const Point& b){ if (a.x == b.x){ return a.y < b.y; } return a.x < b.x;}void msort(LL s, LL t){ LL m, i, j, k; if (s == t) return ; m = (s + t) >> 1; msort(s, m); msort(m+1, t); i = s; j = m + 1; k = s; while (i <= m && j <= t){ if (a[i] > a[j]){ r[k++] = a[i++]; ans += (LL)(t - j + 1); }else{ r[k++] = a[j++]; } } while (i <= m){ r[k++] = a[i++]; } while (j <= t){ r[k++] = a[j++]; } for (i=s; i<=t; i++) a[i] = r[i];}int main(){ scanf("%lld", &n); for (LL i=1; i<=n; i++) scanf("%lld%lld", &P[i].x, &P[i].y); sort(P+1, P+n+1, cmp); for (LL i=1; i<=n; i++) a[i] = P[i].y; msort(1, n); cout << ans << endl; return 0;}
阅读全文
0 0
- 51nod1107(斜率小于0的连线个数)
- 51nod 1107 斜率小于0的连线数量
- 斜率小于0的连线数量 51Nod
- 51nod 1107 斜率小于0的连线数量
- 斜率小于0的连线数量 51NOD
- 51 nod 1107 斜率小于0的连线数量
- 51Nod 1107 斜率小于0的连线数量
- 1107 斜率小于0的连线数量
- 斜率小于0的连线数量-归并排序
- 1107 斜率小于0的连线数量 求逆序对
- 斜率小于0的连线数量,逆序对
- 51nod 1107 斜率小于0的连线的数量 (逆序数)
- 51nod 1107 斜率小于0的连线数量 (树状数组+离线化)
- 51nod-1107 斜率小于0的连线数量(逆序数+离散化)
- 51Nod-1107-斜率小于0的连线数量
- 51nod oj 1107 斜率小于0的连线数量 【类逆序数】
- 51NOD 1107 斜率小于0的连线数量 坐标离散化+树状数组
- 51nod-斜率小于0的连线数量(树状数组+离散化)
- 线段树练习4
- B
- (2)sql 学习 : CONCAT ,SQL JOIN,union 与 union all,SELECT INTO
- Linux中的通配符
- THINKPHP安装XDEBUG
- 51nod1107(斜率小于0的连线个数)
- 1078. Hashing (25)
- Android上类似于iOS相机滑动切换的View
- Mysql与Oracle区别
- ios面试题,各大企业常见的ios面试题之一
- 学习日记5
- poj 2454 随机
- 【洛谷1801】黑匣子
- Kaggle竞赛 —— 泰坦尼克号(Titanic)