ZOJ 3157 Weapon
题意:就是CF round# 329 B 的升级版,要求出相交点的个数
分析:逆序数用树状数组维护,求出非逆序数,然后所有情况(n * (n - 1)) / 2减之就是逆序数个数。
#include <bits/stdc++.h>
using namespace std; const int N = 1e4 + 10;
const double EPS = 1e-8; double x[N][2], y[N][2];
pair<double, double> a[N];
double A[N]; struct BIT {
int c[N], sz;
void init(int n) {
sz = n;
memset (c, 0, sizeof (c));
}
void updata(int i, int x) {
while (i <= sz) {
c[i] += x; i += i & (-i);
}
}
int query(int i) {
int ret = 0;
while (i) {
ret += c[i]; i -= i & (-i);
}
return ret;
}
}bit; int dcmp(double x) {
if (fabs (x) < EPS) return 0;
else return x < 0 ? -1 : 1;
} double cross(int i, double X) {
// if (dcmp (x[i][0] - x[i][1]) == 0) return 0;
double k = y[i][1] - y[i][0];
k /= (x[i][1] - x[i][0]);
double b = -k * x[i][0] + y[i][0];
return k * X + b;
} int main(void) {
int n;
while (scanf ("%d", &n) == 1) {
for (int i=0; i<n; ++i) {
scanf ("%lf%lf%lf%lf", &x[i][0], &y[i][0], &x[i][1], &y[i][1]);
}
double L, R; scanf ("%lf%lf", &L, &R);
L += EPS; R -= EPS;
for (int i=0; i<n; ++i) {
a[i].first = cross (i, L);
a[i].second = cross (i, R);
cout << a[i].first << " " << a[i].second << endl;
}
sort (a, a+n);
for (int i=0; i<n; ++i) A[i] = a[i].second;
sort (A, A+n);
int tot = unique (A, A+n) - A;
bit.init (n);
int ans = 0;
for (int i=0; i<n; ++i) {
int pos = lower_bound (A, A+tot, a[i].second) - A + 1;
ans += bit.query (pos);
bit.updata (pos, 1);
}
printf ("%d\n", n * (n - 1) / 2 - ans);
} return 0;
}
ZOJ 3157 Weapon的更多相关文章
- zoj 3157 Weapon 逆序数/树状数组
B - Weapon Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submit Sta ...
- ZOJ 3157 Weapon --计算几何+树状数组
题意:给一些直线,问这些直线在直线x=L,x=R之间有多少个交点. 讲解见此文:http://blog.sina.com.cn/s/blog_778e7c6e0100q64a.html 首先将直线分别 ...
- ZOJ - 3157:Weapon (几何 逆序对)
pro:给定平面上N条直线,保证没有直线和Y轴平行. 求有多少交点的X坐标落在(L,R)开区间之间,注意在x=L或者R处的不算. sol:求出每条直线与L和R的交点,如果A直线和B直线在(L,R)相交 ...
- 【转载】图论 500题——主要为hdu/poj/zoj
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...
- ZOJ 3684 Destroy
Destroy Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on ZJU. Original ID: 36 ...
- ZOJ 1654 Place the Robots (二分匹配 )
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=654 Robert is a famous engineer. One ...
- ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...
- ZOJ 3686 A Simple Tree Problem
A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a rooted tree, each no ...
- ZOJ Problem Set - 1394 Polar Explorer
这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...
随机推荐
- 3月20,html
html,表格的练习: 1,给图片做链接<br /><img src="200712211720988_2.jpg" usemap="A" w ...
- 畅通工程再续(MST)
畅通工程再续 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- SGU 170 Particles(规律题)
题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=170 解题报告:输入两个由'+'和'-'组成的字符串,让你判断第二个串能不能由第一个 ...
- 2维特征Feature2D(转)
转自:http://blog.csdn.net/yang_xian521/article/details/6901762 主要介绍的是如何用SURF进行特征匹配,和SIFT的使用方法基本一致.
- Linux Apache 怎么修改工作模式
Apache默认为prefork模式,主要是考虑到稳定性的原因. 要切换到worker模式,则需要登录到linux上,进行如下操作: 进入/usr/sbin目录 cd /usr/sbin 将当前的pr ...
- linux安装setup工具
如果你的Linux系统是最小化安装的,可能会没有setup命令工具,环境是centos 5.8 安装setup命令工具的步骤. 安装setuptool #yum install setuptool 系 ...
- mysql中binary相加的问题
我在mysql中有这样一段代码 SQL code ? 1 2 3 4 5 6 7 8 declare @byte1 binary(1) declare @byte2 binary(1) decla ...
- abstract class和interface的区别
1. 引言 2. 概念引入 ●什么是接口? 接口是包含一组虚方法的抽象类型,其中每一种方法都有其名称.参数和返回值.接口方法不能包含任何实现,CLR允许接口可以包含事件.属性.索引 器.静态方法.静态 ...
- Xenomai 安装准备工作
一些安装xenomai的参考资料: http://my.oschina.net/hevakelcj/blog/124290 http://blog.sina.com.cn/s/blog_60b9ee1 ...
- 修剪花卉(codevs 1794)
题目描述 Description ZZ对数学饱有兴趣,并且是个勤奋好学的学生,总是在课后留在教室向老师请教一些问题. 一天他早晨骑车去上课,路上见到一个老伯正在修剪花花草草,顿时想到了一个有关修剪花卉 ...