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 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 <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 10001
#define eps 1e-6
const int inf=0x7fffffff; //无限大
int N;
struct node
{
double x;
double y;
};
double d[maxn];
node point1[maxn],point2[maxn];
node kiss[maxn],kill[maxn];
int lowbit(int x)
{
return x&(-x);
} void update1(int x)
{
while(x<=N)
{
d[x]++;
x+=lowbit(x);
}
} void update2(int x,int num)
{
while(x>)
{
d[x]+=num;
x-=lowbit(x);
}
} int getSum1(int x)
{
int s=;
while(x>)
{
s+=d[x];
x-=lowbit(x);
}
return s;
} bool cmp(node x,node y)
{
if(x.x==y.x)
return x.y<y.y;
return x.x<y.x;
}
int main()
{
sspeed;
int n;
while(cin>>n)
{
memset(d,,sizeof(d));
N=n;
for(int i=;i<n;i++)
{
cin>>point1[i].x>>point1[i].y>>point2[i].x>>point2[i].y;
}
double l,r;
cin>>l>>r;
l+=eps;
r-=eps;
for(int i=;i<n;i++)
{
double k;
k=(point2[i].y-point1[i].y)/(point2[i].x-point1[i].x);
kill[i].x=k*(l-point2[i].x)+point2[i].y;
kill[i].y=k*(r-point2[i].x)+point2[i].y;//求出
}
ll ans=;
sort(kill,kill+n,cmp);
for(int i=;i<n;i++)
{
kiss[i].x=kill[i].y;
kiss[i].y=i+;
}
sort(kiss,kiss+n,cmp);
for(int i=n-;i>=;i--)
{
ans+=getSum1(kiss[i].y);
update1(kiss[i].y);
}
cout<<ans<<endl;
}
return ;
}

zoj 3157 Weapon 逆序数/树状数组的更多相关文章

  1. POJ 2299 Ultra-QuickSort 逆序数 树状数组 归并排序 线段树

    题目链接:http://poj.org/problem?id=2299 求逆序数的经典题,求逆序数可用树状数组,归并排序,线段树求解,本文给出树状数组,归并排序,线段树的解法. 归并排序: #incl ...

  2. Ultra-QuickSort---poj2299 (归并排序.逆序数.树状数组.离散化)

    题目链接:http://poj.org/problem?id=2299 题意就是求把数组按从小到大的顺序排列,每次只能交换相邻的两个数, 求至少交换了几次 就是求逆序数 #include<std ...

  3. ACM学习历程—HDU5592 ZYB's Premutation(逆序数 && 树状数组 && 二分)(BestCoder Round #65 1003)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5592 题目大意就是给了每个[1, i]区间逆序对的个数,要求复原原序列. 比赛的时候2B了一发. 首先 ...

  4. cdoj 841 休生伤杜景死惊开 逆序数/树状数组

    休生伤杜景死惊开 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) 陆伯言军陷八卦 ...

  5. hdu 1394 Minimum Inversion Number 逆序数/树状数组

    Minimum Inversion Number Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showprob ...

  6. [BZOJ 3295] [luogu 3157] [CQOI2011]动态逆序对(树状数组套权值线段树)

    [BZOJ 3295] [luogu 3157] [CQOI2011] 动态逆序对 (树状数组套权值线段树) 题面 给出一个长度为n的排列,每次操作删除一个数,求每次操作前排列逆序对的个数 分析 每次 ...

  7. Bzoj 2141: 排队 分块,逆序对,树状数组

    2141: 排队 Time Limit: 4 Sec  Memory Limit: 259 MBSubmit: 1310  Solved: 517[Submit][Status][Discuss] D ...

  8. 求逆序对[树状数组] jdoj

    求逆序对 题目大意:给你一个序列,求逆序对个数. 注释:n<=$10^5$. 此题显然可以跑暴力.想枚举1到n,再求在i的后缀中有多少比i小的,统计答案即可.这显然是$n^2$的.这...显然过 ...

  9. 洛谷 P1908 逆序对(树状数组解法)

    归并排序解法:https://www.cnblogs.com/lipeiyi520/p/10356882.html 题目描述 猫猫TOM和小老鼠JERRY最近又较量上了,但是毕竟都是成年人,他们已经不 ...

随机推荐

  1. setInterval做定时器

    <script src="/js/jquery-1.8.3.min.js"></script> <script> $(function () { ...

  2. HDU 2825 Wireless Password

    题目链接:HDU-2825 题意:给出m个单词,要构造出满足包含其中大于等于k个单词的字符串,字符只包括小写字母,问长度为n的这样的串有多少个. 思路:令dp[i][j][k]表示当前已经构造了i个字 ...

  3. 读书笔记 effective c++ Item 42 理解typename的两种涵义

    1. class和typename含义相同的例子 问题:在下面的模板声明中class和typename的区别是什么? template<class T> class Widget; // ...

  4. jdbc一次性采集mysql和oracle的海量数据,5000W+为例

    最近做的采集工具遇到采集一天数据(超过5000W行数据)的情况, 采集mysql的时候直接采用流式读取的方式可以一次全部都读取出来,速度的话取决于网络速度 stmt = conn.createStat ...

  5. vue总结07 常用插件

    插件 开发插件 插件通常会为 Vue 添加全局功能.插件的范围没有限制——一般有下面几种: 添加全局方法或者属性,如: vue-custom-element 添加全局资源:指令/过滤器/过渡等,如 v ...

  6. SQLAlchemy-对象关系教程ORM-query

    一:对象关系教程查询 一个 Query创建对象时使用 Session的query()方法 .此函数接受一个变量数量的参数,可以是任何类和class-instrumented描述符的组合. Query返 ...

  7. XP远程连接Win10,提示【远程计算机需要网络级别身份验证,而您的计算机不支持该验证】

    最近电脑安装了Win10系统,在办公室可以通过其他电脑远程,但是回去后使用自己的电脑(XP系统)进行远程提示失败, 提示[远程计算机需要网络级别身份验证,而您的计算机不支持该验证],然后上网查找资料, ...

  8. tf.metrics.accuracy ==>坑货

    tf.metrics.accuracy输出两个值,第一个值为上几步的平均精度,第二值是上几步与该步的精度的平均值. 正常的计算单个batch正确率的代码 self.correct_prediction ...

  9. SQL SERVER中查询某个表或某个索引是否存在

    查询某个表是否存在: 在实际应用中可能需要删除某个表,在删除之前最好先判断一下此表是否存在,以防止返回错误信息.在SQL SERVER中可通过以下语句实现: IF OBJECT_ID(N'表名称', ...

  10. 首次加载进来DEV控件列表第一行颜色总是不对,后台代码显示的数据正确

    1:行改变的颜色正确的颜色: 1.1颜色效果如下图: 1.2:设置行改变颜色: 2:结果首次加载第一行颜色为: 3:解决方案: 3.1 :Views-->OptionsSelection --& ...