题目传送门

题意:就是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的更多相关文章

  1. zoj 3157 Weapon 逆序数/树状数组

    B - Weapon Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Sta ...

  2. ZOJ 3157 Weapon --计算几何+树状数组

    题意:给一些直线,问这些直线在直线x=L,x=R之间有多少个交点. 讲解见此文:http://blog.sina.com.cn/s/blog_778e7c6e0100q64a.html 首先将直线分别 ...

  3. ZOJ - 3157:Weapon (几何 逆序对)

    pro:给定平面上N条直线,保证没有直线和Y轴平行. 求有多少交点的X坐标落在(L,R)开区间之间,注意在x=L或者R处的不算. sol:求出每条直线与L和R的交点,如果A直线和B直线在(L,R)相交 ...

  4. 【转载】图论 500题——主要为hdu/poj/zoj

    转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

  5. ZOJ 3684 Destroy

    Destroy Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on ZJU. Original ID: 36 ...

  6. ZOJ 1654 Place the Robots (二分匹配 )

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=654 Robert is a famous engineer. One ...

  7. ZOJ People Counting

    第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ  3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...

  8. ZOJ 3686 A Simple Tree Problem

    A Simple Tree Problem Time Limit: 3 Seconds      Memory Limit: 65536 KB Given a rooted tree, each no ...

  9. ZOJ Problem Set - 1394 Polar Explorer

    这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...

随机推荐

  1. 淘宝(阿里百川)手机客户端开发日记第八篇 Handler的使用方法

    首先,我们先看下API文档的说明: A Handler allows you to send and process Message and Runnable objects associated w ...

  2. SVN安装与配置 SVN整合MyEclipse

    SVN安装: 1.安装服务器 ######### 安装文件:SVN服务器############### # http://www.collab.net/downloads/subversion # C ...

  3. 03-VTK基础概念(2)

    3.3 光照 剧场里有各式各样的灯光,三维渲染场景中也一样,可以有多个光照存在.光照和相机是三维渲染场景必备的因素,如果没有指定(像3.1.1_RenderCylinder例子,我们没有给Render ...

  4. Java获取、删除文件和目录

    package javatest; import java.io.File; import java.util.ArrayList; import java.util.regex.Pattern; c ...

  5. MySQL性能优化的最佳经验

    今天,数据库的操作越来越成为整个应用的性能瓶颈了,这点对于Web应用尤其明显.关于数据库的性能,这并不只是DBA才需要担心的事,而这更是我们程序员需要去关注的事情.当我们去设计数据库表结构,对操作数据 ...

  6. C++纯虚函数

    本文较为深入的分析了C++中虚函数与纯虚函数的用法,对于学习和掌握面向对象程序设计来说是至关重要的.具体内容如下: 首先,面向对象程序设计(object-oriented programming)的核 ...

  7. 【原创】Mapped Statements collection does not contain value for DaoImpl.method

    问题: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.Pers ...

  8. static_cast dynamic_cast const_cast reinterpret_cast总结对比

    [本文链接] http://www.cnblogs.com/hellogiser/p/static_cast-dynamic_cast-const_cast-reinterpret_cast.html ...

  9. Java for LeetCode 031 Next Permutation

    Next Permutation Total Accepted: 33595 Total Submissions: 134095     Implement next permutation, whi ...

  10. 昂贵的聘礼(poj 1062)

    Description 年轻的探险家来到了一个印第安部落里.在那里他和酋长的女儿相爱了,于是便向酋长去求亲.酋长要他用10000个金币作为聘礼才答应把女儿嫁给他.探险家拿不出这么多金币,便请求酋长降低 ...