sgu209:Areas(计算几何)
意甲冠军:
给一些直。这架飞机被分成了很多这些线性块。每个块的需求面积封闭曲线图。
分析:
①我们应要求交点22的直线;
②每行上的交点的重排序,借此来离散一整行(正反两条边);
③对于连向一个点的几条线段,对它们进行极角排序,相邻的两条线段我们给它们之间连一条边,我们脑补一下应该能够知道如何能够保证逆时针连边;
④找循环,利用叉积求面积。
ps. vector的调试真心不爽…
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#define pb push_back
#include <utility>
#define fi first
#define se second
#define mp make_pair
#include <stack>
using namespace std;
const int MAXN = 100;
const int MAXE = MAXN*MAXN<<1;
const double eps = 1e-8;
typedef double DB;
int n;
#define sqr(x) ((x)*(x))
struct pot
{
double x, y;
pot(double x = 0, double y = 0):x(x), y(y){}
inline double len() {return sqrt(sqr(x)+sqr(y));}
inline void read() {scanf("%lf%lf", &x, &y);}
inline pot unit()
{
double d = len();
return pot(x/d, y/d);
}
inline double ang() {return atan2(y, x);}
};
typedef pot vec;
struct Line
{
pot p;
vec v;
Line(){}
Line(pot p, vec v):p(p), v(v){}
}lines[MAXN];
vector<pot> points;
struct Edge
{
int sz;
int head[MAXE], to[MAXE], ne[MAXE];
Edge()
{
sz = 0;
memset(head, -1, sizeof(head));
}
inline void add(int u, int v)
{
to[sz] = v;ne[sz] = head[u];
head[u] = sz++;
}
}E;
int next[MAXE];
bool vis[MAXE];
vector<DB> ans;
inline int dcmp(double x)
{
if(fabs(x) <= eps) return 0;
else return x>0?1:-1;
}
inline pot operator + (const vec &a, const vec &b) {return vec(a.x+b.x, a.y+b.y);}
inline pot operator - (const vec &a, const vec &b) {return vec(a.x-b.x, a.y-b.y);}
inline double operator * (const vec &a, const vec &b) {return a.x*b.x+a.y*b.y;}
inline double operator ^ (const vec &a, const vec &b) {return a.x*b.y-a.y*b.x;}
inline pot operator * (const vec &a, double k) {return vec(a.x*k, a.y*k);}
inline pot operator / (const vec &a, double k) {return vec(a.x/k, a.y/k);}
inline bool operator < (const vec &a, const vec &b) {return dcmp(a.x-b.x) < 0 || (dcmp(a.x-b.x) == 0 && dcmp(a.y-b.y) < 0);}
inline bool operator == (const vec &a, const vec &b) {return dcmp(a.x-b.x) == 0 && dcmp(a.y-b.y) == 0;}
inline pot get_line_intersection(const pot &p, const vec &v, const pot &q, const vec &w)
{
vec u = p-q;
double t = (w^u)/(v^w);
return p+v*t;
}
inline bool parallel(const Line &a, const Line &b) {return dcmp(a.v^b.v) == 0;}
inline int get_pot_id(const pot &p) {return lower_bound(points.begin(), points.end(), p)-points.begin();}
inline bool cmp(DB a, DB b) {return dcmp(a-b) == 0;}
inline void init()
{
scanf("%d", &n);
for(int i = 0; i < n; ++i)
{
pot a, b;
a.read();b.read();
lines[i] = Line(a, b-a);
}
for(int i = 0; i < n; ++i)
for(int j = i+1; j < n; ++j)
if(!parallel(lines[i], lines[j]))
points.pb(get_line_intersection(lines[i].p, lines[i].v, lines[j].p, lines[j].v));
sort(points.begin(), points.end());
points.erase(unique(points.begin(), points.end()), points.end());
for(int i = 0; i < n; ++i)
{
vector<DB> nodes;
vec d = lines[i].v.unit();
for(int j = 0; j < n; ++j)
if(!parallel(lines[i], lines[j]))
{
pot inter = get_line_intersection(lines[i].p, lines[i].v, lines[j].p, lines[j].v);
nodes.pb((inter-lines[i].p)*d);
}
sort(nodes.begin(), nodes.end());
nodes.erase(unique(nodes.begin(), nodes.end(), cmp), nodes.end());
for(int j = 1, sz = nodes.size(); j < sz; ++j)
{
int a = get_pot_id(lines[i].p+d*nodes[j]);
int b = get_pot_id(lines[i].p+d*nodes[j-1]);
E.add(a, b);E.add(b, a);
}
}
memset(next, -1, sizeof(next));
for(int i = 0, sz = points.size(); i < sz; ++i)
{
vector<pair<DB, int> > PA;
for(int j = E.head[i]; j != -1; j = E.ne[j])
PA.pb(mp((points[E.to[j]]-points[i]).ang(), j));
sort(PA.begin(), PA.end());
for(int j = 0, sz = PA.size(); j < sz; ++j)
next[PA[(j+1)%sz].se^1] = PA[j].se;
}
}
inline void work()
{
for(int i = 0; i < E.sz; ++i)
if(!vis[i])
{
stack<int> s;
int j = i;
do
{
if(!s.empty() && (s.top()^1) == j)
s.pop();
else s.push(j);
vis[j] = true;
j = next[j];
if(j == -1) break;
}while(!vis[j]);
if(i == j)
{
DB area = 0;
while(!s.empty())
{
area += (points[E.to[s.top()^1]]^points[E.to[s.top()]]);
s.pop();
}
area *= 0.5;
if(dcmp(area) > 0)
ans.pb(area);
}
}
}
inline void print()
{
printf("%d\n", ans.size());
sort(ans.begin(), ans.end());
for(int i = 0, sz = ans.size(); i < sz; ++i)
printf("%.4lf\n", ans[i]);
}
int main()
{
init();
work();
print();
return 0;
}
版权声明:本文博主原创文章,博客,未经同意不得转载。
sgu209:Areas(计算几何)的更多相关文章
- ASP.NET Core 中文文档 第四章 MVC(4.6)Areas(区域)
原文:Areas 作者:Dhananjay Kumar 和 Rick Anderson 翻译:耿晓亮(Blue) 校对:许登洋(Seay) Areas 是 ASP.NET MVC 用来将相关功能组织成 ...
- 【无私分享:ASP.NET CORE 项目实战(第九章)】创建区域Areas,添加TagHelper
目录索引 [无私分享:ASP.NET CORE 项目实战]目录索引 简介 在Asp.net Core VS2015中,我们发现还有很多不太简便的地方,比如右击添加视图,转到试图页等功能图不见了,虽然我 ...
- ASP.NET MVC Routing、Areas、URLs
webForm页面运行起来url一般是这样的:localhost:****/index.aspx,这个过程就是当你运行页面的时候,vs开发工具自带的微型服务器会打开你存在硬盘上的这个文件然后显示在浏览 ...
- ACM/ICPC 之 计算几何入门-叉积-to left test(POJ2318-POJ2398)
POJ2318 本题需要运用to left test不断判断点处于哪个分区,并统计分区的点个数(保证点不在边界和界外),用来做叉积入门题很合适 //计算几何-叉积入门题 //Time:157Ms Me ...
- HDU 2202 计算几何
最大三角形 Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- [转]【无私分享:ASP.NET CORE 项目实战(第九章)】创建区域Areas,添加TagHelper
本文转自:http://www.cnblogs.com/zhangxiaolei521/p/5808417.html 目录索引 [无私分享:ASP.NET CORE 项目实战]目录索引 简介 在Asp ...
- ACM 计算几何中的精度问题(转)
http://www.cnblogs.com/acsmile/archive/2011/05/09/2040918.html 计算几何头疼的地方一般在于代码量大和精度问题,代码量问题只要平时注意积累模 ...
- Areas on the Cross-Section Diagram
Areas on the Cross-Section Diagram Aizu - ALDS1_3_D Areas on the Cross-Section Diagram 地域の治水対策として.洪 ...
- Asp.Net Mvc Areas 的用法与好处
前言 在项目中为什么要使用Areas 进行分离 大家都知道,一般的Web应用都有前台(面向用户)和后台(面向管理员)两部分,我们希望以/localhost/Admin 开始的Url 是用户的后台管理地 ...
随机推荐
- ganglia错误解决
1. 运行: 解决: 这时重新启动gmetad,输入命令: service gmetad stop 显示: Shutting down GANGLIA gmetad: ...
- 2、HZK和FreeType的使用
HZK16汉字库的使用 定义如下: unsigned char str[]="我" 在运行时str被初始化为2个字节长度,内容为“我”的GBK码,为:0xCE(区码),0xD2(位 ...
- eclipse调试鼠标放上去显示变量值
在eclipse中调试时,鼠标移动到变量上不显示值,这个原来自己也遇到过,没注意,反正就使用ctrl+shift+i嘛,也可以的,刚查了一下,解决方法如下: Window->Preference ...
- Linux上制作Window启动盘
Linux上制作Window启动盘 注意: U盘在Linux中的标签(依具体情况而定:执行df查看) U盘 ----- /dev/sdb4 格式化U盘 建立U盘的启动分区 安装关键工具 ms-sys ...
- hadoop容灾能力测试 分类: A1_HADOOP 2015-03-02 09:38 291人阅读 评论(0) 收藏
实验简单来讲就是 1. put 一个600M文件,分散3个replica x 9个block 共18个blocks到4个datanode 2. 我关掉了两个datanode,使得大部分的block只在 ...
- nslookup详解(name server lookup)( 域名查询)
nslookup详解(name server lookup)( 域名查询) 一.总结 1.爬虫倒是很方便拿到页面数据:a.网页的页面源码我们可以轻松获得 b.比如cnsd博客,文章的正文内容全部放在 ...
- 向 Windows 高级用户进阶,这 10 款效率工具帮你开路 | 新手问号
原文地址:https://sspai.com/post/41411 编注:「新手问号」是少数派的一个全新栏目.它面向完全「零基础」的新手用户,通过最简单易懂的方式,帮助你快速掌握关于系统和软硬件的入门 ...
- rabbitMQ服务安装
1.rabbitMQ简介 1.1.rabbitMQ的优点(适用范围)1. 基于erlang语言开发具有高可用高并发的优点,适合集群服务器.2. 健壮.稳定.易用.跨平台.支持多种语言.文档齐全.3. ...
- 在RedHa上安装MRTG监控网卡流量
http://os.51cto.com/art/201103/252149.htm 2011-03-30 15:05 张微波 phpchina 字号:T | T 在RedHa上安装MRTG监控网卡流量 ...
- android 发送http请求
好久没写博客了,由于公司要做android,笔者也是第一次接触. 这是在项目中遇到一个比較麻烦的问题.记录下来备忘(本人刚接触.有不正确的地方请不吝赐教). 发送请求的代码: package com. ...