BZOJ2494 Triangles and Quadrangle
一道非常"简单"的计算几何题。。。
题意:给你两个三角形和一个四边形,问你能否用这两个三角形拼成这个四边形
首先。。。四边形可能是凹四边形。。。需要判断一下。。。这个比较简单直接分成两部分即可。。。
然后。。。四边形可能会退化成三角形。。。那就需要两个三角形拼起来的时候某两个角之和为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的更多相关文章
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- Count the number of possible triangles
From: http://www.geeksforgeeks.org/find-number-of-triangles-possible/ Given an unsorted array of pos ...
- [ACM_搜索] Triangles(POJ1471,简单搜索,注意细节)
Description It is always very nice to have little brothers or sisters. You can tease them, lock them ...
- acdream.Triangles(数学推导)
Triangles Time Limit:1000MS Memory Limit:64000KB 64bit IO Format:%lld & %llu Submit Stat ...
- UVA 12651 Triangles
You will be given N points on a circle. You must write a program to determine how many distinctequil ...
- Codeforces Gym 100015F Fighting for Triangles 状压DP
Fighting for Triangles 题目连接: http://codeforces.com/gym/100015/attachments Description Andy and Ralph ...
- 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 ...
- 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 ...
- Project Euler 94:Almost equilateral triangles 几乎等边的三角形
Almost equilateral triangles It is easily proved that no equilateral triangle exists with integral l ...
随机推荐
- 3.29考试(HNOI难度)
一. 城镇 [ town ] Memory Limit: 128 MB Time Limit : 1s Description 在 farmer land 上,有 N 个 farmer to ...
- "npm ERR! Error: EPERM: operation not permitted"问题解决
在基于macaca进行自动化测试的时候,遇到如下问题: E:\AutoTest\Macaca\LocalTEST\macaca-test-sample\macaca-test>macaca do ...
- 编码实现Spring 利用@Resource注解实现bean的注入,xml实现基本数据类型的注入
首先分析. 1: 肯定要利用dom4j读取xml配置文件,将所有的bean的配置信息读取出来 2: 利用反射技术,实例化所有的bean 3: 写注解处理器, 利用注解和内省实现依赖对象的注入. 4: ...
- Spring管理bean的生命周期
1: bean的创建: 如果我们默认的scope配置为Singleton的话, bean的创建实在Spring容器创建的时候创建: 如果scope的配置为Prototype的话,bena的创建是在 ...
- KaliLinux装好系统后安装常用软件
1.配置软件源 leafpad /etc/apt/source.list or(recommand):#官方源deb kali main non-free contribdeb-src kali ma ...
- SpringAop学习
Spring Aop (jdk动态代理和cglib代理) Aop 的概念 aop即面向切面编程,一般解决具有横切面性质的体统(事务,缓存,安全) JDK动态代理: 可以使用实现proxy 类,实现jd ...
- hdu5816 卡特兰数+dp
题意:共n张无中生有,m张攻击牌.每张攻击牌攻击力已知,敌方有p点血.随机洗牌.游戏开始,己方抽取一张手牌,若是无中生有则可再抽两张牌.求能在第一回合内将敌方杀死的概率. n+m <= 20, ...
- 转:HTTP 301 跳转和302跳转的区别
301和302 Http状态有啥区别?301,302 都是HTTP状态的编码,都代表着某个URL发生了转移,不同之处在于: 301 redirect: 301 代表永久性转移(Permanently ...
- poj2187Beauty Contest(凸包直径)
链接 利用旋转卡壳 参考博客http://www.cppblog.com/staryjy/archive/2010/09/25/101412.html #include <iostream> ...
- 【Todo】Mybatis学习-偏理论
之前写过好几篇Mybatis相关的文章: http://www.cnblogs.com/charlesblc/p/5906431.html <SSM(SpringMVC+Spring+Myba ...