ZOJ 3157 Weapon
题意:就是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的更多相关文章
- zoj 3157 Weapon 逆序数/树状数组
B - Weapon Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submit Sta ...
- ZOJ 3157 Weapon --计算几何+树状数组
题意:给一些直线,问这些直线在直线x=L,x=R之间有多少个交点. 讲解见此文:http://blog.sina.com.cn/s/blog_778e7c6e0100q64a.html 首先将直线分别 ...
- ZOJ - 3157:Weapon (几何 逆序对)
pro:给定平面上N条直线,保证没有直线和Y轴平行. 求有多少交点的X坐标落在(L,R)开区间之间,注意在x=L或者R处的不算. sol:求出每条直线与L和R的交点,如果A直线和B直线在(L,R)相交 ...
- 【转载】图论 500题——主要为hdu/poj/zoj
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...
- ZOJ 3684 Destroy
Destroy Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on ZJU. Original ID: 36 ...
- ZOJ 1654 Place the Robots (二分匹配 )
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=654 Robert is a famous engineer. One ...
- ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...
- ZOJ 3686 A Simple Tree Problem
A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a rooted tree, each no ...
- ZOJ Problem Set - 1394 Polar Explorer
这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...
随机推荐
- BI就是报表?
实际上,报表只是BI的一部分,虽然BI应用的结果通常需要通过报表来展示,但是,BI绝对不仅仅是报表.其实,大家对这些概念的理解,如同15年前的ERP一样.1998年,国内两大巨头金蝶与用友都开始宣称从 ...
- 域名在微信朋友圈内分享需要ICP备案 杜绝不良信息传播
就在刚刚,腾讯微信团队发布公告表示域名在朋友圈内分享需要ICP备案,杜绝打击不良互联网信息的传播.公告称根据互联网管理相关规定,即日起在微信朋友圈内分享的域名,请在2014年12月31日前完成ICP备 ...
- 微信公众平台开发(十) 消息回复总结——用其xml模板
一.简介 微信公众平台提供了三种消息回复的格式,即文本回复.音乐回复和图文回复,在这一篇文章中,我们将对这三种消息回复的格式做一下简单讲解,然后封装成函数,以供读者使用. 二.思路分析 对于每一个PO ...
- [Effective JavaScript 笔记] 第10条:避免使用with
with特性,提供的任何“便利”都更让其变得不可靠和低效率. with语句的用法,可以很方便地避免对对象的重复引用.上面的代码整理成下面的形式 function status(info){ var w ...
- js检测是否安装了flash插件
function flashChecker() { var hasFlash = 0; //是否安装了flash var flashVersion = 0; //flash版本 var isIE = ...
- 【JAVA、C++】LeetCode 012 Integer to Roman
Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 t ...
- js简单上传进度条
效果如下:
- Android 设置旋转朝向
在AndroidMenifest.xml中activity标签中,添加一个属性 android:screenOrientation="landscape"
- July 16th, Week 29th Saturday, 2016
A long road tests a horse's strength and a long task proves a man's heart. 路遥知马力,日久见人心. Do you have ...
- 膜拜(codevs 3369)
3369 膜拜 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description 神牛有很多…当然…每个同学都有自己衷心膜拜的 ...