Weapon

Time Limit: 1000 msMemory Limit: 32768 KB

In World War 3, your countries‘ scientists have invented a special weapon. Assume that the enemy‘s city can be described by rectangular coordinates and it has n roads which are all lines. None of the road is paralled with Y-axis. Besides, each road is represented by two different points (ai,bi) (ci,di) on it. Any three roads will not intersect at one point.

This special weapon can destroy all the castles whose x coordinate belongs to (l,r). After spying, you know that all the castles are set in the crossing point of two roads and in each crossing point there is a castle. In addition, each road‘s end-point‘s x coordinate does not belong to (l,r).

The scientists want to check the weapon‘s effect. If its effect can not reach army‘s expectation, they have to spend more time and more money in expanding its range. Obviously, the number of castles it can destroy plays an important role on the effect. So you are asked to calculate how many castles can be destroyed by this special weapon.

Input

Input contains multiple cases.

Every test case, the first line is an integers n (2 <= n <= 10000). Then n lines follow. The (i+1)-th line contains four integers ai,bi,ci,di (-1E8 <= ai,bi,ci,di <= 1E8). The (n+2)-th line contains two doubles l,r (-1E8 <= l,r <= 1E8) There is a blank line between two cases.

Output

For each case, output the number of castles that can be destroyed by the weapon.

Sample Input

3
0 0 1 1
2 0 1 1
0 0 2 0
0 2.5

Sample Output

2
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 1e5 + 108;
const ll mod = 1e9 + 7;
int ooo = 800;

int n;

struct Line {
    double k, b;
} o[maxn];

struct point {
    double l, r;
    int pos;
} s[maxn];

double L, R;

bool cmp1(point S, point T) {
    return S.l <= T.l;
}

bool cmp2(point S, point T) {
    return S.r <= T.r;
}

int sum[maxn];

inline void pushup(int rt) {
    sum[rt] = sum[rt << 1] + sum[rt << 1 | 1];
}

inline void build(int rt, int l, int r) {
    if (l == r) {
        sum[rt] = 0;
        return;
    }
    int mid = l + r >> 1;
    build(rt << 1, l, mid);
    build(rt << 1 | 1, mid + 1, r);
    pushup(rt);
}

inline void update(int rt, int l, int r, int pos, int val) {
    if (l == r) {
        sum[rt] += val;
        return;
    }
    int mid = l + r >> 1;
    if (pos <= mid) {
        update(rt << 1, l, mid, pos, val);
    } else {
        update(rt << 1 | 1, mid + 1, r, pos, val);
    }
    pushup(rt);
}

inline int query(int rt, int l, int r, int ql, int qr) {
    if (ql <= l && qr >= r) {
        return sum[rt];
    }
    int mid = l + r >> 1, cur = 0;
    if (ql <= mid) {
        cur += query(rt << 1, l, mid, ql, qr);
    }
    if (qr > mid) {
        cur += query(rt << 1 | 1, mid + 1, r, ql, qr);
    }
    return cur;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("1.txt", "r", stdin);
#endif
    while (scanf("%d", &n) != EOF) {
        for (register int i = 1; i <= n; ++i) {
            double x1, y1, x2, y2;
            scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);
            o[i].k = (y2 - y1) / (x2 - x1);
            o[i].b = y1 - o[i].k * x1;
        }
        scanf("%lf%lf", &L, &R);
        L += 1e-8;
        R -= 1e-8;
        for (register int i = 1; i <= n; ++i) {
            s[i].l = o[i].k * L + o[i].b;
            s[i].r = o[i].k * R + o[i].b;
        }
        sort(s + 1, s + 1 + n, cmp1);
        for (register int i = 1; i <= n; ++i) {
            s[i].pos = i;
        }
        sort(s + 1, s + 1 + n, cmp2);
        int res = 0;
        build(1, 1, n);
        for (register int i = 1; i <= n; ++i) {
            update(1, 1, n, s[i].pos, 1);
            res += i - query(1, 1, n, 1, s[i].pos);
        }
        printf("%d\n", res);
    }
    return 0;
}

原文地址:https://www.cnblogs.com/czy-power/p/11470475.html

时间: 2024-11-13 10:00:53

Weapon的相关文章

按要求编写Java应用程序: (1)编写西游记人物类(XiYouJiRenWu) 其中属性有:身高(height),名字(name),武器(weapon) 方法有:显示名字(printName),显示武器(printWeapon) (2)在主类的main方法中创建二个对象:zhuBaJie,sunWuKong。并分别为他 们的两个属性(name,weapon)赋值,最后分别调用printName,

package com.hanqi.test; public class xiyoujirenwu { int height; String name; String weapon; xiyoujirenwu(String na,String wp ) { name=na; weapon=wp; } String printName() { return name; } String printWeapon() { return weapon; } } //主类 package com.hanq

[Document]翻Projectile Weapon的时候发现的一些可能有用的东西

Firing Mode Definition /************************************************************************************ * Firing Mode Definition ***********************************************************************************/ /** * This enum defines the fir

The charactor bring the weapon

<pre class="cpp" name="code">/* *Copyright(c)2016,烟台大学计算机与控制工程学院 *All rights reserved *文件名称:123.cpp *作 者:隋宗涛 *完成日期:2016年5月8日 *版 本 号:v1.0 * *问题描述:在上周的游戏角色类基础上扩充,为每个角色创建一个武器,并在攻击行为发生时,武器在其中起作用,设计一个武器类,其数据成员至少要有武器名.威力 *输入描述: *程序输出:

zoj 3157 Weapon 逆序数/树状数组

B - Weapon Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Description In World War 3, your countries' scientists have invented a special weapon. Assume that the enemy's city can be described by rectangular co

Dancing Links - nuclear weapon for Exact Cover problems

http://www.cnblogs.com/grenet/p/3145800.htmlBest elaboration on dancing list I found. in Chinese. Traditional backtracing is a heuristic-like procedure. Say, there are N items to try with one by one, when N[i] is picked, all rest N[i + 1, N-1] items

zoj 3157 Weapon 线段树求逆序对数

题目链接:http://www.icpc.moe/onlinejudge/showProblem.do?problemId=3128 题意:平面上有n条直线,给出l, r,求出这些直线的交点横坐标在(l, r)范围内的个数. 思路: 首先求出每条直线与直线x = l和直线x = r的交点,如下图. 因为题目要求区间(l, r)是开区间,所以为了避免交点的横坐标刚好是l或者r的情况,可以先把l加上一个很小的值,r减去一个很小的值,如图中的灰线. 然后求出各条直线与两条灰线的交点,首先按与l的交点的

One parenting weapon

Number One Parenting Tool There is only one main parenting tool that must be used to develop your child emotional behavior. I know that sounds unreal. How could there be just one main thing to do with all of the information available that prescribes

java设计模式--工厂模式

总结 (1)简单工厂模式是由一个具体的类去创建其他类的实例,父类是相同的,父类是具体的. (2)工厂方法模式是有一个抽象的父类定义公共接口,子类负责生成具体的对象,这样做的目的是将类的实例化操作延迟到子类中完成. (3)抽象工厂模式提供一个创建一系列相关或相互依赖对象的接口,而无须指定他们具体的类.它针对的是有多个产品的等级结构.而工厂方法模式针对的是一个产品的等级结构. 一.工厂模式主要是为创建对象提供过渡接口,以便将创建对象的具体过程屏蔽隔离起来,达到提高灵活性的目的. 工厂模式在<Java

Python之路【第五篇】:面向对象编程

面向对象编程思维导向图 http://naotu.baidu.com/file/03516c91377d6cad0ded041aa4ce4433?token=ccaba09527261666 密码: Tim 面向:过程.函数.对象 面向过程:根据业务逻辑从上到下写垒代码! 面向过程的编程弊:每次调用的时候都的重写,代码特别长,代码重用性没有,每次增加新功能所有的代码都的修改!那有什么办法解决上面出现的弊端呢?函数就出现了. 面向函数:将某功能代码封装到函数中,日后便无需重复编写,仅调用函数即可!