题目传送门

题意:就是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. 昂贵的聘礼(dijkstra)

    昂贵的聘礼 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 38549   Accepted: 11158 Descripti ...

  2. nginx(四)初识nginx日志文件

    nginx 日志相关指令主要有两条,一条是log_format,用来设置日志格式,另外一条是access_log,用来指定日志文件的存放路径.格式和缓存大小,通俗的理解就是先用log_format来定 ...

  3. apache virtualhost配置 apache配置多个网站

    第一步 apache下httpd.conf文件 启用模块LoadModule vhost_alias_module modules/mod_vhost_alias.so 第二步 apache下http ...

  4. MySQL 如何只导出 指定的表 的表结构和数据 ( 转 )

    MySQL 如何只导出 指定的表 的表结构和数据 ( 转 ) 2011-01-04 15:03:33 分类: MySQL MySQL 如何只导出 指定的表 的表结构和数据 导出更个库的表结构如下:my ...

  5. C# Dictionary和Dynamic类型

    开发中需要传递变参,考虑使用 dynamic 还是 Dictionary(准确地说是Dictionary<string,object>).dynamic 的编码体验显著优于 Diction ...

  6. 《ASP.NET MVC4 WEB编程》学习笔记------Web API 续

    目录 ASP.NET WEB API的出现缘由 ASP.NET WEB API的强大功能 ASP.NET WEB API的出现缘由 随着UI AJAX 请求适量的增加,ASP.NET MVC基于Jso ...

  7. vs2013秘钥

    Ultimate:BWG7X-J98B3-W34RT-33B3R-JVYW9 Premium:FBJVC-3CMTX-D8DVP-RTQCT-92494  YKCW6-BPFPF-BT8C9-7DCT ...

  8. 31.从尾到头输出链表[Print linked list from last to first]

    [题目] 输入一个链表的头结点,从尾到头反过来输出每个结点的值. [分析] 这是一道很有意思的面试题.该题以及它的变体经常出现在各大公司的面试.笔试题中. [链表逆置] 看到这道题后,第一反应是从头到 ...

  9. iOS 在使用UINavigationController和TabBarController时view的frame

    可能是以前记错了,总认为在ios6上使用了UINavigationController或者TabBarController会因为多了bar而影响子controller的view的frame大小.今天在 ...

  10. Objective-C ,C++,java中常用编码格式对比

    这个题目可能不太对!主要总结一下这3种语言的不同格式 1.创建一个A类,继承B类,实现C接口(协议) 先看oc的代码 @interface A : B <C> { int a; } @pr ...