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的更多相关文章

  1. Codeforces 599D Spongebob and Squares(数学)

    D. Spongebob and Squares Spongebob is already tired trying to reason his weird actions and calculati ...

  2. codeforces 314E Sereja and Squares

    discription Sereja painted n points on the plane, point number i (1 ≤ i ≤ n) has coordinates (i, 0). ...

  3. codeforces 425D Sereja and Squares n个点构成多少个正方形

    输入n个点,问可以构成多少个正方形.n,xi,yi<=100,000. 刚看题的时候感觉好像以前见过╮(╯▽╰)╭最近越来越觉得以前见过的题偶尔就出现类似的,可是以前不努力啊,没做出来的没认真研 ...

  4. CodeForces 610B Vika and Squares

    #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using ...

  5. Codeforces.314E.Sereja and Squares(DP)

    题目链接 http://www.cnblogs.com/TheRoadToTheGold/p/8443668.html \(Description\) 给你一个擦去了部分左括号和全部右括号的括号序列, ...

  6. codeforces 599D Spongebob and Squares

    很容易得到n × m的方块数是 然后就是个求和的问题了,枚举两者中小的那个n ≤ m. 然后就是转化成a*m + c = x了.a,m≥0,x ≥ c.最坏是n^3 ≤ x,至于中间会不会爆,测下1e ...

  7. 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 ...

  8. 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/ ...

  9. 【27.40%】【codeforces 599D】Spongebob and Squares

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

随机推荐

  1. 10: vue-router和单文件组件

    1.1 vue-router路由基本使用 官网: https://router.vuejs.org/zh/api/#router-link 1.安装vue-router bower info vue- ...

  2. 20155201 网络攻防技术 实验五 MSF基础应用

    20155201 网络攻防技术 实验五 MSF基础应用 一.实践内容 一个主动攻击实践,如ms08_067 一个针对浏览器的攻击,如ms11_050 一个针对客户端的攻击,如Adobe 成功应用任何一 ...

  3. Codeforces 868C Qualification Rounds - 位运算

    Snark and Philip are preparing the problemset for the upcoming pre-qualification round for semi-quar ...

  4. Docker 入门指南——常用命令

    前面已经介绍了 Docker 的安装方式,本文总结一下使用 Docker 的基本概念和常用命令. 基本概念 镜像 Image 镜像是一些打包好的已有的环境,可以被用来启动和创建容器 容器 Contai ...

  5. linux如何使make输出makefile中所有的规则和变量

    答: make -p (会执行makefile,加入-q可以阻止makefile的执行)

  6. tp框架中的一些疑点知识-6

    vim自带一个目录浏览器,使用命令:E就可以调出来,实际上就是浏览器的名字就是"网络读写"netrw vim也自带了 补全功能, 启动键是 "ctrl_N" 或 ...

  7. UVALive 7501 Business Cycle(二分)题解

    题意:n个数,有一个起始值,按顺序从第一个开始不断循环取数,如果取完后相加小于0就变为0,最多取p个数,问你得到大于等于值g所需要的最小起始值为多少 思路:这题目爆long long爆的毫无准备,到处 ...

  8. 深入浅出JavaScript(一)

    数据类型 1. 六种数据类型 JavaScript包含六种数据类型:基本类型number.string.boolean.null.undefined和对象类型Object.其中,对象类型包含方法fun ...

  9. Learning to Track at 100 FPS with Deep Regression Networks ECCV 2016 论文笔记

    Learning to Track at 100 FPS with Deep Regression Networks   ECCV 2016  论文笔记 工程网页:http://davheld.git ...

  10. [LightOJ 1370] Bi-shoe and Phi-shoe(欧拉函数快速筛法)

    题目链接: https://vjudge.net/problem/LightOJ-1370 题目描述: 给出一些数字,对于每个数字找到一个欧拉函数值大于等于这个数的数,求找到的所有数的最小和. 知识点 ...