一道非常"简单"的计算几何题。。。

题意:给你两个三角形和一个四边形,问你能否用这两个三角形拼成这个四边形

首先。。。四边形可能是凹四边形。。。需要判断一下。。。这个比较简单直接分成两部分即可。。。

然后。。。四边形可能会退化成三角形。。。那就需要两个三角形拼起来的时候某两个角之和为180°

最后暴力一下如何划分四边形即可。。。

写的真是开心,还好一遍A了QAQ

 /**************************************************************
Problem: 2494
User: rausen
Language: C++
Result: Accepted
Time:8 ms
Memory:820 kb
****************************************************************/ #include <cstdio>
#include <cmath>
#include <algorithm> using namespace std;
typedef double lf; template <class T> inline T sqr(const T &x) {
return x * x;
} template <class T> inline int sgn(const T &x) {
const T eps = 1e-;
if (fabs(x) < eps) return ;
return x < ? - : ;
} struct point {
lf x, y;
point() {}
point(lf _x, lf _y) : x(_x), y(_y) {} inline point operator + (const point &p) const {
return point(x + p.x, y + p.y);
}
inline point operator - (const point &p) const {
return point(x - p.x, y - p.y);
}
inline lf operator * (const point &p) const {
return x * p.y - y * p.x;
}
inline point operator * (const lf &d) const {
return point(x * d, y * d);
}
inline void get() {
scanf("%lf%lf", &x, &y);
}
friend inline lf dis2(const point &p) {
return sqr(p.x) + sqr(p.y);
}
friend inline lf dis(const point &p) {
return sqrt(dis2(p));
}
} t[][], p[]; inline bool check(const point &a, const point &b, const point &c, const int &p) {
static lf T1[], T2[];
static int i;
T1[] = dis(a - b), T1[] = dis(b - c), T1[] = dis(c - a);
for (i = ; i < ; ++i)
T2[i] = dis(t[p][i] - t[p][i + ]);
sort(T1, T1 + ), sort(T2, T2 + );
for (i = ; i < ; ++i)
if (sgn(T1[i] - T2[i]) != ) return ;
return ;
} inline point get_cross(const point &a, const point &b, const point &c, const point &d) {
static lf rate;
rate = / ( - ((d - c) * (b - c)) / ((d - c) * (a - c)));
return (b - a) * rate + a;
} int main() {
int T, icase, i, j, f;
lf di[], d1;
point p1, a, b, c, d, e;
scanf("%d", &T);
for (icase = ; icase <= T; ++icase) {
f = ;
for (i = ; i < ; ++i) t[][i].get(), t[][i + ] = t[][i];
for (i = ; i < ; ++i) t[][i].get(), t[][i + ] = t[][i];
for (i = ; i < ; ++i) p[i].get(), p[i + ] = p[i]; for (i = ; i < ; ++i)
di[i] = dis(t[][i] - t[][i + ]), di[i + ] = dis(t[][i] - t[][i + ]);
if (((p[] - p[]) * (p[] - p[])) * ((p[] - p[]) * (p[] - p[])) < ) {
if (check(p[], p[], p[], ) && check(p[], p[], p[], )) f = ;
if (check(p[], p[], p[], ) && check(p[], p[], p[], )) f = ;
}
if (((p[] - p[]) * (p[] - p[])) * ((p[] - p[]) * (p[] - p[])) < ) {
if (check(p[], p[], p[], ) && check(p[], p[], p[], )) f = ;
if (check(p[], p[], p[], ) && check(p[], p[], p[], )) f = ;
} for (i = ; i < ; ++i) {
a = p[i], b = p[i + ], c = p[i + ], d = p[i + ];
if (((b - a) * (c - a)) * ((b - a) * (d - a)) < ) {
e = get_cross(a, b, c, d);
if (check(a, d, e, ) && check(b, c, e, )) f = ;
if (check(a, d, e, ) && check(b, c, e, )) f = ;
}
}
for (i = ; i < ; ++i) if (sgn((p[i + ] - p[i]) * (p[i + ] - p[i])) == ) {
d1 = dis(p[i + ] - p[i]);
for (j = ; j < ; ++j) if (d1 >= di[j]) {
p1 = p[i + ] - p[i];
p1 = p1 * (di[j] / d1) + p[i];
if (check(p[i + ], p[i], p1, ) && check(p[i + ], p[i + ], p1, )) f = ;
if (check(p[i + ], p[i], p1, ) && check(p[i + ], p[i + ], p1, )) f = ;
}
}
printf("Case #%d: %s\n", icase, f ? "Yes" : "No");
}
return ;
}

BZOJ2494 Triangles and Quadrangle的更多相关文章

  1. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  2. Count the number of possible triangles

    From: http://www.geeksforgeeks.org/find-number-of-triangles-possible/ Given an unsorted array of pos ...

  3. [ACM_搜索] Triangles(POJ1471,简单搜索,注意细节)

    Description It is always very nice to have little brothers or sisters. You can tease them, lock them ...

  4. acdream.Triangles(数学推导)

    Triangles Time Limit:1000MS     Memory Limit:64000KB     64bit IO Format:%lld & %llu Submit Stat ...

  5. UVA 12651 Triangles

    You will be given N points on a circle. You must write a program to determine how many distinctequil ...

  6. Codeforces Gym 100015F Fighting for Triangles 状压DP

    Fighting for Triangles 题目连接: http://codeforces.com/gym/100015/attachments Description Andy and Ralph ...

  7. Codeforces Round #309 (Div. 1) C. Love Triangles dfs

    C. Love Triangles Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/553/pro ...

  8. Codeforces Round #308 (Div. 2) D. Vanya and Triangles 水题

    D. Vanya and Triangles Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55 ...

  9. Project Euler 94:Almost equilateral triangles 几乎等边的三角形

    Almost equilateral triangles It is easily proved that no equilateral triangle exists with integral l ...

随机推荐

  1. 比Redis更快:Berkeley DB面面观

    比Redis更快:Berkeley DB面面观 Redis很火,最近大家用的多.从两年前开始,Memcached转向Redis逐渐成为潮流:而Berkeley DB可能很多朋友还很陌生,首先,我们简单 ...

  2. windows下使用xShell远程连接virtualbox里面的linux

    第一阶段:基本安装 安装virtual box 在virtualbox里面安装xubuntu:是ubuntu+xfce桌面环境的一个linux的发行版本 在windows下安装Xmanager Ent ...

  3. unity3d中asset store 的资源下载到本地的目录位置

    来源:http://blog.csdn.net/fzhlee/article/details/8613688 C:/Users/[当前用户]/AppData/Roaming/Unity/Asset S ...

  4. DB层面上的设计 分库分表 读写分离 集群化 负载均衡

    第1章  引言 随着互联网应用的广泛普及,海量数据的存储和访问成为了系统设计的瓶颈问题.对于一个大型的 互联网应用,每天几十亿的PV无疑对数据库造成了相当高的负载.对于系统的稳定性和扩展性造成了极大的 ...

  5. PHP爬虫抓取网页内容 (simple_html_dom.php)

    使用simple_html_dom.php,下载|文档 因为抓取的只是一个网页,所以比较简单,整个网站的下次再研究,可能用Python来做爬虫会好些. <meta http-equiv=&quo ...

  6. Scrum Meeting---Six(2015-11-1)

    说明 由于周五放假,我们团队部分队员回家和外出,所以这一次的Scrum Meeting我们推迟到周日晚上,在周末的这段时间内队员对自己做的任务在周日晚汇报给我. 周末完成任务以及周一计划任务 姓名 周 ...

  7. Hibernate 对象的三种状态

    hibernate对象的三种状态: (一) 瞬时(临时)状态:   对象被创建时的状态,数据库里面没有与之对应的记录! (二) 持久状态:   处于session的管理中,并且数据库里面存在与之对应的 ...

  8. html一般标签、常用标签、表格

    body的属性: bgcolor               页面背景色 text                    文字颜色 topmargin            上边距 leftmargi ...

  9. 树的计数 + prufer序列与Cayley公式 学习笔记

    首先是 Martrix67 的博文:http://www.matrix67.com/blog/archives/682 然后是morejarphone同学的博文:http://blog.csdn.ne ...

  10. JavaWeb学习总结(十五)--过滤器的应用

    一.解决全站字符乱码(post和get中文编码问题) 乱码问题: 获取请求参数中的乱码问题: POST请求:request.setCharacterEncoding("utf-8" ...