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时间修改-hwclock和date

    修改系统时间date 设定日期:date -s 月/日/年,例如设定日期为2018年12月1日,date -s 12/01/2018(年也可以是两位) 设定时间:date -s hh:mm:ss,例如 ...

  2. golang BDD testcase framework.

    BDD What is Behaviour Driven Development and why should I care? Behaviour Driven Development (BDD) i ...

  3. Linux普通用户使用sudo免输密码(Debian/Redhat通用)

    今天使用的Debian,由于使用的是普通用户,而使用的sudo都需要输入密码的繁琐操作, 下面是使用sudo时免输入密码. 需要管理员权限进行以下操作. 修改sudoers vim /etc/sudo ...

  4. topcoder srm 315 div1

    problem1  link 直接模拟即可. import java.util.*; import java.math.*; import static java.lang.Math.*; publi ...

  5. ODAC(V9.5.15) 学习笔记(十三)TOraMetaData

    通过TOraMetaData控件获取Oracle数据库对象信息,首先需要设置MetaDataKind属性,然后设置Restrictions属性设置条件,最后通过激活数据集获取信息,演示代码如下: Me ...

  6. Python3基础 list enumerate 将列表的每个元素转换成 带索引值的元组

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  7. P4313 文理分科

    思路 遇到这种利益冲突的最终利益最大化问题 考虑转化为最小割,使得损失的价值最小 相当于文科是S,理科是T,选出最小割就是确定损失代价最小的方案 然后就把S向每个点连一条cap=art[i][j]的边 ...

  8. 论文笔记:Learning Dynamic Memory Networks for Object Tracking

    Learning Dynamic Memory Networks for Object Tracking  ECCV 2018Updated on 2018-08-05 16:36:30 Paper: ...

  9. 良好的GUI设计指南

    一.设计指南 摘自:<需求分析与系统设计(第3版)> 7.1.2. 1. 用户控制 用户事件(菜单动作.鼠标点击.屏幕光标移动等)打开GUI窗口或调用程序:程序执行需要反馈到用户. 2.  ...

  10. 所有JTAG集成电路都应该支持菊花链

    菊花链 在电气和电子工程中,菊花链是一种布线方案,其中多个设备按顺序或环形连接在一起.相邻设备才能通信.菊花链可用于电源,模拟信号,数字数据或其组合. 但是由于菊花链的串联特性,如果任何一个设备从链路 ...