SGU 209. Areas
209. Areas
memory limit per test: 65536 KB
output: standard
Your task in this problem is for each finite part to find its area.
All coordinates do not exceed 102 by their absolute value.
No two lines coincide.
Next K lines of the output file must contain area parts sorted in non-decreasing order. You answer must be accurate up to 10-4.
Due to floating point precision losses possible, do not consider parts with area not exceeding 10-8.
0 0 1 0
1 0 1 1
1 1 0 1
0 1 0 0
0 0 1 1
0.5000
0.5000
题意
求平面上一堆直线围成的所有封闭多边形面积。
ID: | Date'n'Time: | Name: | Task: | .Ext: | Status: | Time: | Memory: |
1587815 | 27.08.14 15:40 | HuZhifeng | 209 | .CPP | Accepted | 15 ms | 458 kb |
1587814 | 27.08.14 15:00 | HuZhifeng | 209 | .CPP | Wrong answer on test 12 | 15 ms | 554 kb |
1587813 | 27.08.14 14:55 | HuZhifeng | 209 | .CPP | Memory Limit Exceeded on test 12 | 218 ms | 99406 kb |
1587812 | 27.08.14 14:53 | HuZhifeng | 209 | .CPP | Runtime Error on test 12 | 15 ms | 378 kb |
#include <bits/stdc++.h>
#define rep(_i, _j) for(int _i = 1; _i <= _j; ++_i)
const int inf = 0x3f3f3f3f;
typedef long long LL;
typedef double DB;
using namespace std;
/*{ 基本定义,二维点,向量,叉积,点积,基本运算。*/ const DB eps = 1e-;
#define sqr(x) ((x) * (x))
int dcmp(DB x) {
return x < -eps ? - : eps < x;
}
bool chk_equality(DB x, DB y) {
return dcmp(x - y) == ;
} struct Point {
DB x, y;
Point() {}
Point(DB x, DB y): x(x), y(y) {}
DB arg() {
return atan2(y, x);
}
DB norm() {
return sqrt(sqr(x) + sqr(y));
}
Point normalize() {
DB d = norm();
return Point(x / d, y / d);
}
void read() {
scanf("%lf%lf", &x, &y);
}
};
typedef Point Vector;
bool operator == (const Point a, const Point b) {
return dcmp(a.x - b.x) == && dcmp(a.y - b.y) == ;
}
bool operator < (const Point a, const Point b) {
return dcmp(a.x - b.x) < || (dcmp(a.x - b.x) == && dcmp(a.y - b.y) < );
}
Vector operator + (Point a, Point b) {
return Vector(a.x + b.x, a.y + b.y);
}
Vector operator - (Point a, Point b) {
return Vector(a.x - b.x, a.y - b.y);
}
Vector operator * (Vector v, DB p) {
return Vector(v.x * p, v.y * p);
}
Vector operator / (Vector v, DB p) {
return Vector(v.x / p, v.y / p);
}
DB dot(Vector a, Vector b) {
return a.x * b.x + a.y * b.y;
}
DB cross(Vector a, Vector b) {
return a.x * b.y - a.y * b.x;
}
DB length(Vector a) {
return sqrt(dot(a, a));
} /*} end*/ struct Line {
Point p;
Vector d;
Line() {}
Line(Point p, Vector d): p(p), d(d) {}
};
bool operator == (Line a, Line b) {
return a.p == b.p && dcmp(cross(a.d, b.d)) == ;
}
/*{ 常用函数*/ Point get_intersection(Line a, Line b) {
DB s1 = cross(a.p - b.p, b.d);
DB s2 = cross(a.p + a.d - b.p, b.d);
return (a.p * s2 - (a.p + a.d) * s1) / (s2 - s1);
} /*} end*/ const int maxn = + ; int n;
Line lines[maxn];
Point tmp1, tmp2;
vector<Point> points;
int get_point_id(Point a) {
return lower_bound(points.begin(), points.end(), a) - points.begin();
}
const int maxv = maxn;
const int maxe = maxv * maxv * ;
struct Edge {
int edge;
int head[maxe], to[maxe], next[maxe];
Edge() {
edge = ;
memset(head, -, sizeof head);
}
void addedge(int u, int v) {
to[edge] = v;
next[edge] = head[u];
head[u] = edge++;
}
} E;
int next[maxe];
bool vis[maxe]; int main() {
#ifndef ONLINE_JUDGE
freopen("209.in", "r", stdin); freopen("209.out", "w", stdout);
#endif
cin >> n;
for(int i = ; i < n; ++i) {
tmp1.read(), tmp2.read();
lines[i] = Line(tmp1, tmp2 - tmp1);
}
for(int i = ; i < n; ++i) {
for(int j = ; j < i; ++j) {
if(!chk_equality(cross(lines[i].d, lines[j].d), )) {
points.push_back(Point(get_intersection(lines[i], lines[j])));
}
}
}
sort(points.begin(), points.end());
points.erase(unique(points.begin(), points.end()), points.end());
for(int i = ; i < n; ++i) {
vector<DB> lambdas;
Vector d = lines[i].d.normalize();
for(int j = ; j < n; ++j) {
if(!chk_equality(cross(d, lines[j].d), )) {
lambdas.push_back(dot(get_intersection(lines[i], lines[j]) - lines[i].p, d));
}
}
sort(lambdas.begin(), lambdas.end());
lambdas.erase(unique(lambdas.begin(), lambdas.end(), chk_equality), lambdas.end());
for(int j = , sz = lambdas.size(); j < sz; ++j) {
int a = get_point_id(lines[i].p + d * lambdas[j]);
int b = get_point_id(lines[i].p + d * lambdas[j - ]);
E.addedge(b, a);
E.addedge(a, b);
}
}
memset(next, -, sizeof next);
for(int i = , sz = points.size(); i < sz; ++i) {
vector<pair<DB, int> > adjacent;
for(int j = E.head[i]; j != -; j = E.next[j]) {
adjacent.push_back(make_pair((points[E.to[j]] - points[i]).arg(), j));
}
sort(adjacent.begin(), adjacent.end());
for(int j = , sz = adjacent.size(); j < sz; ++j) {
next[adjacent[(j + ) % sz].second ^ ] = adjacent[j].second;
}
}
memset(vis, false, sizeof vis);
vector<DB> areas;
for(int i = ; i < E.edge; ++i) {
if(!vis[i]) {
vector<int> boundary;
int j = i;
do {
if(!boundary.empty() && (boundary.back() ^ j) == ) {
boundary.pop_back();
} else {
boundary.push_back(j);
}
vis[j] = true;
j = next[j];
} while(!vis[j]);
if(i == j) {
DB area = 0.0;
for(int k = , sz = boundary.size(); k < sz; ++k) {
area += cross(points[E.to[boundary[k] ^ ]], points[E.to[boundary[k]]]);
}
area /= 2.0;
if(dcmp(area) > ) {
areas.push_back(area);
}
}
}
}
sort(areas.begin(), areas.end());
printf("%d\n", (int)areas.size());
for(int i = , sz = areas.size(); i < sz; ++i) {
printf("%.4lf\n", areas[i]);
}
return ;
}
SGU 209. 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开发工具自带的微型服务器会打开你存在硬盘上的这个文件然后显示在浏览 ...
- [转]【无私分享:ASP.NET CORE 项目实战(第九章)】创建区域Areas,添加TagHelper
本文转自:http://www.cnblogs.com/zhangxiaolei521/p/5808417.html 目录索引 [无私分享:ASP.NET CORE 项目实战]目录索引 简介 在Asp ...
- 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 是用户的后台管理地 ...
- SGU 495. Kids and Prizes
水概率....SGU里难得的水题.... 495. Kids and Prizes Time limit per test: 0.5 second(s)Memory limit: 262144 kil ...
- ACM: SGU 101 Domino- 欧拉回路-并查集
sgu 101 - Domino Time Limit:250MS Memory Limit:4096KB 64bit IO Format:%I64d & %I64u Desc ...
- 【SGU】495. Kids and Prizes
http://acm.sgu.ru/problem.php?contest=0&problem=495 题意:N个箱子M个人,初始N个箱子都有一个礼物,M个人依次等概率取一个箱子,如果有礼物则 ...
随机推荐
- 【翻译】InterlockedIncrement内部是如何实现的?
Interlocked系列函数可以对内存进行原子操作,它是如何实现的? 它的实现依赖于底层的CPU架构.对于某些CPU来说,这很简单,例如x86可以通过LOCK前缀直接支持Interl ...
- Hdu1542 Atlantis
Atlantis Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
- php前后端分离项目跨域问题解决办法
由于之前一直没有做过前后端分离项目,导致走了不少弯路,而且还采用了一种及其不优雅的方法 (在第一次请求的时候把服务器返回的session id保存起来,后续请求的时候把该session id作为参数传 ...
- Linux安全之SYN攻击原理及处理
TCP自从1974年被发明出来之后,历经30多年发展,目前成为最重要的互联网基础协议,但TCP协议中也存在一些缺陷. SYN攻击就是利用TCP协议的缺陷,来导致系统服务停止正常的响应. SYN攻击原理 ...
- python常用函数库及模块巧妙用法汇总
在用python编写脚本或写程序过程中总要遇到一些对大文件或数据进行排序,计算,循环跌代等.我想下面这些函数库一定能用得到,总结如下:便于以后备查 列表去重(传说是列表去重最高效的方法): al = ...
- MySQL性能优化之道
1.in和not in子查询优化 not in 是不能命中索引的,所以以下子查询性能很低. 如果是确定且有限的集合时,可以使用.如 IN (0,1,2). 用 exists或 notexists代替 ...
- [linux]linux下安装mysql
1.安装g++$sudo apt-get install build-essential注:此命令会同时安装gcc和make2.安装cmake$sudo apt-get install cmake3. ...
- 【BZOJ】2125: 最短路 圆方树(静态仙人掌)
[题意]给定带边权仙人掌图,Q次询问两点间最短距离.n,m,Q<=10000 [算法]圆方树处理仙人掌问题 [题解]树上的两点间最短路问题,常用倍增求LCA解决,考虑扩展到仙人掌图. 先对仙人掌 ...
- 【CodeForces】915 D. Almost Acyclic Graph 拓扑排序找环
[题目]D. Almost Acyclic Graph [题意]给定n个点的有向图(无重边),问能否删除一条边使得全图无环.n<=500,m<=10^5. [算法]拓扑排序 [题解]找到一 ...
- (值类型引用类型)和null的关系
1.null null表示变量没有指向任何对象. 2.值类型 包括 bool.结构体.枚举.int.double.float等等 .在.NET中值类型都继承自ValueType. 3. 引 ...