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 是用户的后台管理地 ...
随机推荐
- 【拆分版】 Docker-compose构建Logstash多实例,基于7.1.0
[拆分版]Docker-compose构建Logstash多实例 写在最前 说起Logstash,这个组件并没有什么集群的概念,与其说是集群,不如说是各自去收集日志分析过滤存储到Elasticsear ...
- stm32的ADC左右对齐
- Android中ImageView.ScaleType属性值
1 android:scaleType="center" (1)当图片大于ImageView的宽高:以图片的中心点和ImageView的中心点为基准,按照图片的原大小居中显示,不缩 ...
- PostgreSQL 序列
PostgreSQL 中的序列是一个数据库对象,本质上是一个自增器.因此,序列在其他同类型数据库软件中以 autoincrment 值的形式存在.在一张表需要非随机,唯一标实符的场景下,Sequenc ...
- POJ 2823 Sliding Window 线段树
http://poj.org/problem?id=2823 出太阳啦~^ ^被子拿去晒了~晚上还要数学建模,刚才躺在床上休息一下就睡着了,哼,还好我强大,没有感冒. 话说今年校运会怎么没下雨!!!说 ...
- 运行一个Hadoop Job所需要指定的属性 分类: A1_HADOOP 2015-02-02 21:33 231人阅读 评论(0) 收藏
1.设置job的基础属性 Job job = new Job(); job.setJarByClass(***.class); job.setJobName("job name") ...
- 魔兽争霸war3心得体会(三):UD内战
最近,经常匹配到UD内战.有输有赢,有的时候,自己双矿经济,人口优势巨大,却很遗憾地输掉比赛. 本文,简要分析下 对战过程. 前期狗流开局, 5只狗,一只出去骚扰,攻击商店,防止对方科技蜘蛛骚扰我.二 ...
- 【27.85%】【codeforces 743D】Chloe and pleasant prizes
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- [React] Cleanly Map Over A Stateless Functional Component with a Higher Order Component
In this lesson we'll create a Higher Order Component (HOC) that takes care of the key property that ...
- Android学习笔记:Home Screen Widgets(2):关于Widget
通过widget定义,我们在widget列表中看到了我们的TestWidget.当我们拖拽widget到主页时,假设在appwidet-provider中定义了android:configure的ja ...