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. Linux LAMP架构搭建

    一.部署LAMP基本架构 1.L(linux)A(apache)M(mysql)P(php) 2.稳定版本(mysql5.1,php5.3,apache2.2) 3.安装顺序,mysql-->a ...

  2. Js扩容

    /*脚本统一调用工具(企业端)*/ //杂项工具 var MiscUtils = { //去除字符串中所有的空格 ClearStringEmpty: function (str) { var strR ...

  3. C# 发送16进制串口数据

    一个困扰两天的问题:需要通过串口向设备发送的数据:0A010 7e 08 00 11 00 00 7e 76 7f我先将每个16进制字符转换成10进制,再将其转换成ASCII码对应的字符. /// & ...

  4. JS深拷贝/深克隆(面试用)

    晒下我的比较浅显的深拷贝,没有考虑原型和循环引用,可以拷贝一些js原生类型,用于面试用. function deepClone(obj){ if(Object.prototype.toString.c ...

  5. topcoder srm 490 div1

    problem1 link 首先每$n*m$一定是一个循环,所以只需要考虑时间$[0,n*m-1]$即可.这个期间一共出现了$n$个,第i个的出现时间为$m*i$,离开的时间为$\left \lcei ...

  6. 给ThinkPad E470C 换个高分屏(1080P)

  7. 再谈fedora下的音乐和视频播放器的安装

    rpm包就相当于windows下的exe,已经是编译后的二进制代码,可以使用rpm命令或dnf install ???.rpm来安装 lnux下软件的安装跟windows不同, 后者要到处去找, 要做 ...

  8. P2596 [ZJOI2006]书架

    思路 一开始写fhq-treap 感觉越写越感觉splay好些,就去splay 然后维护序列 注意前驱后继的不存在的情况 但不用插入虚拟节点(那插入岂不太麻烦) 跑的真慢的一批,splay太多了 错误 ...

  9. 关于#ifdef #ifndef

    https://www.cnblogs.com/agnily/p/5848768.html 1.先看#ifdef的用法: #define KEY1_PA0 #ifdef KEY1_PA0 ------ ...

  10. sudo用法记录

    使用root用户,visudo命令(实际是编辑/etc/sudoers文件),用法和vim一样,末行模式:wq退出,如还有提示,使用大写"Q"保存退出,小写"e" ...