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

  1. 3
  2. 0 0 1 1
  3. 2 0 1 1
  4. 0 0 2 0
  5. 0 2.5

Sample Output

  1. 2
  1. #include <cstdio>
  2. #include <cmath>
  3. #include <cstring>
  4. #include <ctime>
  5. #include <iostream>
  6. #include <algorithm>
  7. #include <set>
  8. #include <vector>
  9. #include <sstream>
  10. #include <queue>
  11. #include <typeinfo>
  12. #include <fstream>
  13. typedef long long ll;
  14. using namespace std;
  15. //freopen("D.in","r",stdin);
  16. //freopen("D.out","w",stdout);
  17. #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
  18. #define maxn 10001
  19. #define eps 1e-6
  20. const int inf=0x7fffffff; //无限大
  21. int N;
  22. struct node
  23. {
  24. double x;
  25. double y;
  26. };
  27. double d[maxn];
  28. node point1[maxn],point2[maxn];
  29. node kiss[maxn],kill[maxn];
  30. int lowbit(int x)
  31. {
  32. return x&(-x);
  33. }
  34.  
  35. void update1(int x)
  36. {
  37. while(x<=N)
  38. {
  39. d[x]++;
  40. x+=lowbit(x);
  41. }
  42. }
  43.  
  44. void update2(int x,int num)
  45. {
  46. while(x>)
  47. {
  48. d[x]+=num;
  49. x-=lowbit(x);
  50. }
  51. }
  52.  
  53. int getSum1(int x)
  54. {
  55. int s=;
  56. while(x>)
  57. {
  58. s+=d[x];
  59. x-=lowbit(x);
  60. }
  61. return s;
  62. }
  63.  
  64. bool cmp(node x,node y)
  65. {
  66. if(x.x==y.x)
  67. return x.y<y.y;
  68. return x.x<y.x;
  69. }
  70. int main()
  71. {
  72. sspeed;
  73. int n;
  74. while(cin>>n)
  75. {
  76. memset(d,,sizeof(d));
  77. N=n;
  78. for(int i=;i<n;i++)
  79. {
  80. cin>>point1[i].x>>point1[i].y>>point2[i].x>>point2[i].y;
  81. }
  82. double l,r;
  83. cin>>l>>r;
  84. l+=eps;
  85. r-=eps;
  86. for(int i=;i<n;i++)
  87. {
  88. double k;
  89. k=(point2[i].y-point1[i].y)/(point2[i].x-point1[i].x);
  90. kill[i].x=k*(l-point2[i].x)+point2[i].y;
  91. kill[i].y=k*(r-point2[i].x)+point2[i].y;//求出
  92. }
  93. ll ans=;
  94. sort(kill,kill+n,cmp);
  95. for(int i=;i<n;i++)
  96. {
  97. kiss[i].x=kill[i].y;
  98. kiss[i].y=i+;
  99. }
  100. sort(kiss,kiss+n,cmp);
  101. for(int i=n-;i>=;i--)
  102. {
  103. ans+=getSum1(kiss[i].y);
  104. update1(kiss[i].y);
  105. }
  106. cout<<ans<<endl;
  107. }
  108. return ;
  109. }

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. Ubuntu下安装arm-linux-gnueabi-xxx编译器【转】

    转自:http://blog.csdn.net/real_myth/article/details/51481639 from: http://www.linuxdiyf.com/linux/1948 ...

  2. nginx配置location总结及rewrite规则写法【转】

    转自 nginx配置location总结及rewrite规则写法 | Sean's Noteshttp://seanlook.com/2015/05/17/nginx-location-rewrite ...

  3. Shell编程学习1--基础了解

    "#!path"告诉系统path所指的程序为用来解释此脚本文件的Shell程序: 如#!/bin/sh, #!/bin/bash Shell Script的后缀名为.sh; ech ...

  4. C++ 虚函数及重载、重定义、重写

    #include<iostream> usingnamespace std; class BASE { public: BASE()=default; BASE(int publicVal ...

  5. springboot 零xml集成mybatis-plus

    工程结构 pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns=&quo ...

  6. USACO 5.4 Canada Tour

    Canada Tour You have won a contest sponsored by an airline. The prize is a ticket to travel around C ...

  7. Python全栈开发之15、DOM

    文档对象模型(Document Object Model,DOM)是一种用于HTML和XML文档的编程接口.它给文档提供了一种结构化的表示方法,可以改变文档的内容和呈现方式.我们最为关心的是,DOM把 ...

  8. python opencv入门-形态学转换

    目标: 学习不同的形态操作 例如 腐蚀.膨胀.开运算.闭运算 等. 我们要学习的函数有 cv2.erode(),cv2.dilate(),cv2.morphologyEx() 等. 原理 :一般对二值 ...

  9. HTTP协议--请求与响应

    1.简介 HTTP 是一个属于应用层的面向对象的协议,由于其简捷.快速的方式,适用于分布式超媒体信息系统.它于1990 年提出,经过几年的使用与发展,得到不断地完善和扩展.目前在WWW 中使用的是HT ...

  10. 2018年全国多校算法寒假训练营练习比赛(第一场)J - 闯关的lulu

    链接:https://www.nowcoder.com/acm/contest/67/J来源:牛客网 题目描述 勇者lulu某天进入了一个高度10,000,000层的闯关塔,在塔里每到一层楼,他都会获 ...