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

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

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

然后。。。四边形可能会退化成三角形。。。那就需要两个三角形拼起来的时候某两个角之和为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. Spring管理bean的生命周期

    1: bean的创建:   如果我们默认的scope配置为Singleton的话, bean的创建实在Spring容器创建的时候创建: 如果scope的配置为Prototype的话,bena的创建是在 ...

  2. yii2-获取配置选项的值

    Yii::$app->属性值 e.g:echo Yii::$app->id #输出basic config: $config = [ 'id' => 'basic', 'basePa ...

  3. select into from 和 insert into select 的区别和用法及 SQL SELECT INTO 中Undeclared variable错误解决办法

    今天试了一下数据表中的数据备份到另一个空的数据表,然后使用了SQL SELECT INTO语句,然后提示Undeclared variable......错误,现在在这里做下总结并给出解决办法. 应用 ...

  4. javascript获取类元素

    代码测试是ie5+: 原生javascript中筛选出含有指定类的元素: 思想:在指定范围里把所有的元素筛选出来,然后把里面的每个元素都遍历找出它们含有的所有类,然后逐个元素遍历它们各自的类,如果指定 ...

  5. JS 字符串编码函数(解决URL特殊字符传递问题):escape()、encodeURI()、encodeURIComponent()区别详解

    javaScript中有三个可以对字符串编码的函数,分别是: escape,encodeURI,encodeURIComponent,相应3个解码函数:unescape,decodeURI,decod ...

  6. (三)uboot源码分析

    一.九鼎官方uboot和三星原版uboot对比(1)以九鼎官方的uboot为蓝本来学习的,以三星官方的这份为对照.(2)不同版本的uboot或者同一版本不同人移植的uboot,可能目录结构和文件内容都 ...

  7. SVN标准目录结构

    Trunk 这是SVN目录的主分支,表示日常开发中的项目,任何时候Trunk里包含的都是最新的开发代码. 这里的代码将会工作到你的下一个主要发布版本. Trunk应该只被用来开发将会成为你的下一个重要 ...

  8. 对List里的对象元素进行排序

    public class Student { private int studentId; private String studentName; private int age; public St ...

  9. linux下在jar包中找类是否存在

    find /usr/lib -name "*.jar" -exec grep -Hsli 类名 {} \;

  10. RTB

    RTB —— Real Time Bidding 的简称,就是实时竞价.跟传统购买形式相比,RTB是在每一个广告展示曝光的基础上进行竞价,就是每一个PV都会进行一次展现竞价,谁出价高,谁的广告就会被这 ...