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. log4j2配置推荐

    <?xml version="1.0" encoding="UTF-8"?> <!-- monitorInterval为监听配置变化的间隔,3 ...

  2. 关于A left join B,A是否一定是主表?

    一般情况,我们作左连接 select * from A left join B  on A.id=B.a_id;一定认为A就是主表,其实还有另外的情况,我们若将sql改写成 select * from ...

  3. A writer of dictionaries,a harmless druge.

    Nine Years for A and B By Christopher Ricks Dr. Johnson was the greatest man who made a dictionary.  ...

  4. [c/c++] programming之路(7)、数据类型转换、偷钱小程序、进制转换

    一.数据类型转换 #include<stdio.h> //某些场合,必须进行数据类型转换,以匹配调用 void main0(){ printf();//printf不管你是什么类型,解析失 ...

  5. thiniphp tp5 使用缓存

    在应用或者模块配置文件中配置好所用缓存的类型及相关参数: 如果是文件类型可以用 'cache' => [ 'type' => 'File', 'path' => CACHE_PATH ...

  6. 启动maven的web项目

    一.可以通过在pom中配置tomcat插件. 首先要确保你的仓库里有这个插件,然后按如下配置. <build> <plugins> <!-- 配置Tomcat插件 --& ...

  7. uniGUI试用笔记(二)

    前几天做的demo今天启动后,浏览器打开页面后死活不显示窗体,找了半天原因才发现是360浏览器启动了兼容模式,改成极速模式后就正常了.有点晕.... 今天简单测试了TUniGUIServerModul ...

  8. 三星sm865

    目录 样张 SSD-Z: CrystalDiskInfo: CrystalDiskMark: AS-SSD Benchmark: 颗粒检查: 扇区信息: HD Tune Pro: 三星Magician ...

  9. POJ 1191 棋盘分割(区间DP)题解

    题意:中文题面 思路:不知道直接暴力枚举所有情况行不行... 我们可以把答案转化为 所以答案就是求xi2的最小值,那么我们可以直接用区间DP来写.设dp[x1][y1][x2][y2][k]为x1 y ...

  10. Winform选择目录路径与选择文件路径

    https://blog.csdn.net/zaocha321/article/details/52528279 using System.Collections.Generic; using Sys ...