Codeforces 994 C - Two Squares
思路:
点积叉积应用
代码:
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pii pair<int, int>
#define piii pair<int,pii>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head struct P {
double x, y;
P(){}
P(double x, double y):x(x), y(y) {}
P operator - (P p) {
return P(x-p.x, y-p.y);
}
double cross(P p) {
return x*p.y - y*p.x;
}
double dot(P p) {
return x*p.x + y*p.y;
}
};
typedef P Vector;
bool on_seg(P p, Vector a, Vector b) {
if((a-p).cross(b-p) == && (a-p).dot(b-p) <= ) return true;
else return false;
}
double area2(Vector a, Vector b, Vector c) {
return (b-a).cross(c-a);
}
bool intersect(Vector a, Vector b, Vector c, Vector d) {
if(area2(a, c, d) == && area2(b, c, d) == && !on_seg(a, c, d) && !on_seg(b, c, d)
|| area2(a, c, d) * area2(b, c, d) >
|| area2(c, a, b) * area2(d, a, b) >
) return false;
else return true;
}
pii a[], b[];
int main() {
for (int i = ; i < ; i++) scanf("%d %d", &a[i].fi, &a[i].se);
for (int i = ; i < ; i++) scanf("%d %d", &b[i].fi, &b[i].se);
for (int i = ; i < ; i++) {
for (int j = ; j < ; j++) {
Vector aa(a[i].fi, a[i].se);
Vector bb(a[(i+)%].fi, a[(i+)%].se);
Vector c(b[j].fi, b[j].se);
Vector d(b[(j+)%].fi, b[(j+)%].se);
if(intersect(aa, bb, c, d)) return *puts("YES");
}
}
for (int i = ; i < ; i++) {
int x = , y = , xx = , yy = ;
for (int j = ; j < ; j++) {
Vector A(a[i].fi, a[i].se), B(b[j].fi, b[j].se), C(b[(j+)%].fi, b[(j+)%].se);
if(area2(A, B, C) > ) x++;
else if(area2(A, B, C) < )y++;
else x++, y++;
Vector AA(b[i].fi, b[i].se), BB(a[j].fi, a[j].se), CC(a[(j+)%].fi, a[(j+)%].se);
if(area2(AA, BB, CC) > ) xx++;
else if(area2(AA, BB, CC) < ) yy++;
else xx++, yy++;
}
if(x == || y == || xx == || yy == ) return *puts("YES");
}
puts("NO");
return ;
}
Codeforces 994 C - Two Squares的更多相关文章
- Codeforces 599D Spongebob and Squares(数学)
D. Spongebob and Squares Spongebob is already tired trying to reason his weird actions and calculati ...
- codeforces 314E Sereja and Squares
discription Sereja painted n points on the plane, point number i (1 ≤ i ≤ n) has coordinates (i, 0). ...
- codeforces 425D Sereja and Squares n个点构成多少个正方形
输入n个点,问可以构成多少个正方形.n,xi,yi<=100,000. 刚看题的时候感觉好像以前见过╮(╯▽╰)╭最近越来越觉得以前见过的题偶尔就出现类似的,可是以前不努力啊,没做出来的没认真研 ...
- CodeForces 610B Vika and Squares
#include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using ...
- Codeforces.314E.Sereja and Squares(DP)
题目链接 http://www.cnblogs.com/TheRoadToTheGold/p/8443668.html \(Description\) 给你一个擦去了部分左括号和全部右括号的括号序列, ...
- codeforces 599D Spongebob and Squares
很容易得到n × m的方块数是 然后就是个求和的问题了,枚举两者中小的那个n ≤ m. 然后就是转化成a*m + c = x了.a,m≥0,x ≥ c.最坏是n^3 ≤ x,至于中间会不会爆,测下1e ...
- Codeforces Round #337 (Div. 2) B. Vika and Squares 贪心
B. Vika and Squares 题目连接: http://www.codeforces.com/contest/610/problem/B Description Vika has n jar ...
- Codeforces Round #332 (Div. 2) D. Spongebob and Squares 数学题枚举
D. Spongebob and Squares Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/ ...
- 【27.40%】【codeforces 599D】Spongebob and Squares
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
随机推荐
- HashMap的实现原理总结
HashMap基于hashing原理,我们通过put()和get()方法储存和获取对象. 当我们将键值对传递给put()方法时,它调用键对象的hashCode()方法来计算hashcode,让后找到b ...
- The address where a.out.debug has been loaded is missing以及No symbol "*" in current context原因与解决方法
最近,在debug core的时候,发现p 变量的时候提示“No symbol "*" in current context”,我们的代码使用-g编译的,经查有可能是下列几个原因或 ...
- Linux模拟僵尸进程并kill
模拟系统有僵尸进程后怎么解决 僵尸进程 #include <stdio.h> #include <sys/types.h> int main() { //fork a chil ...
- 转:网卡、光纤网卡、ISCSI卡有什么区别?
网卡.光纤网卡.ISCSI卡有什么区别? 感谢: http://www.it.com.cn/f/server/063/6/241650.htm 在讨论这个问题的时候,需要先说清楚一个问题:我们知道,在 ...
- squid代理服务器安装和配置
服务器版本:centos6.5 squid版本:3.1 Squid介绍 Squid是一个缓存Internet 数据的软件,其接收用户的下载申请,并自动处理所下载的数据.当一个用户想要下载一个主页时,可 ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem E (Codeforces 831E) - 线段树 - 树状数组
Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this int ...
- HTML <frame> 标签的 src 属性
HTML <frame> 标签 实例 src 属性规定在框架中显示的文档的位置: <html> <frameset cols="50%,50%"> ...
- centos设置中文输入法无效的解决办法
安装 im-chooser: yum install im-chooser 回到当前使用的普通用户,设置 ibus 输入法为默认输入系统: imsettings-switch ibus
- 关于link标签的用法, 不声明rel=stylesheet则无效? 在ff中必须声明rel属性!
void 无效的, 空的; invalid: 无效的, void 和 invalid 在表示无效的时候, 是一样的, 等同的 the treaty (条约) was declared invalid ...
- 三星sm865
目录 样张 SSD-Z: CrystalDiskInfo: CrystalDiskMark: AS-SSD Benchmark: 颗粒检查: 扇区信息: HD Tune Pro: 三星Magician ...