C. Two Squares
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect.

The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect.

Input

The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order.

The first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees.

All the values are integer and between −100−100 and 100100.

Output

Print "Yes" if squares intersect, otherwise print "No".

You can print each letter in any case (upper or lower).

Examples
input

Copy
0 0 6 0 6 6 0 6
1 3 3 5 5 3 3 1
output

Copy
YES
input

Copy
0 0 6 0 6 6 0 6
7 3 9 5 11 3 9 1
output

Copy
NO
input

Copy
6 0 6 6 0 6 0 0
7 4 4 7 7 10 10 7
output

Copy
YES
Note

In the first example the second square lies entirely within the first square, so they do intersect.

In the second sample squares do not have any points in common.

Here are images corresponding to the samples:

题意,两个正方形是否相交

题解:1.用叉积判断边是否相交

   2.判断A的中心是否在B内或者B的中心是否在A内

叉积

判断两条线段是否相交

要判断两条线段是否相交,则需要检查每条线段是否跨越了另一条线段的直线。如果点p1位于某直线的一边,而点p2位于该直线的另一边,则称p1p2跨越了这条直线。两条线段相交,当且仅当下面两个条件至少成立一个:

每条线段都跨越了包含另一条线段的直线

一条线段的一个端点落在另一条线段上

#include<bits/stdc++.h>
using namespace std;
#define x first
#define y second
typedef pair<int, int> PII;
int x[][], y[][];//两个正方形的坐标
PII p[][]; //叉积判断是否相交
int cross (PII p1, PII p2, PII p) {
return (p2.x - p1.x) * (p.y - p1.y) - (p.x - p1.x) * (p2.y - p1.y);
} bool ok (int i, int j) {
int flag = ;
for (int k = ; k < ; k++) {
//四个边用叉积判断是否相交或者同侧 if (cross (p[i][], p[i][], p[j][k]) *cross (p[i][], p[i][], p[j][k]) >= &&
cross (p[i][], p[i][], p[j][k]) *cross (p[i][], p[i][], p[j][k]) >= ) {
//判断相交
//两边包一边的思想
flag = ;
}
} //判断A中心是否在B内或者B中心是否在A内
int xx=(p[j][].x + p[j][].x) / ;
int yy=(p[j][].y + p[j][].y) / ;
PII px = PII ( xx, yy);
if (cross (p[i][], p[i][], px) *cross (p[i][], p[i][], px) >= &&
cross (p[i][], p[i][], px) *cross (p[i][], p[i][], px) >= ) {
//判断相交
flag = ;
}
return flag;
} int main() {
int n, m;
//把正方形的点封装到pair内去
for (int i = ; i < ; i++) {
cin >> x[][i] >> y[][i];
p[][i] = PII (x[][i], y[][i]);
}
for (int i = ; i < ; i++) {
cin >> x[][i] >> y[][i];
p[][i] = PII (x[][i], y[][i]);
} int flag = ;
if (ok (, ) || ok (, ) ) flag = ;
printf ("%s\n", flag ? "YES" : "NO");
return ;
}

 

code forces 994C的更多相关文章

  1. 思维题--code forces round# 551 div.2

    思维题--code forces round# 551 div.2 题目 D. Serval and Rooted Tree time limit per test 2 seconds memory ...

  2. Code Forces 796C Bank Hacking(贪心)

    Code Forces 796C Bank Hacking 题目大意 给一棵树,有\(n\)个点,\(n-1\)条边,现在让你决策出一个点作为起点,去掉这个点,然后这个点连接的所有点权值+=1,然后再 ...

  3. Code Forces 833 A The Meaningless Game(思维,数学)

    Code Forces 833 A The Meaningless Game 题目大意 有两个人玩游戏,每轮给出一个自然数k,赢得人乘k^2,输得人乘k,给出最后两个人的分数,问两个人能否达到这个分数 ...

  4. Code Forces 543A Writing Code

    题目描述 Programmers working on a large project have just received a task to write exactly mm lines of c ...

  5. code forces 383 Arpa's loud Owf and Mehrdad's evil plan(有向图最小环)

    Arpa's loud Owf and Mehrdad's evil plan time limit per test 1 second memory limit per test 256 megab ...

  6. code forces 382 D Taxes(数论--哥德巴赫猜想)

    Taxes time limit per test 2 seconds memory limit per test 256 megabytes input standard input output ...

  7. code forces Watermelon

    /* * Watermelon.cpp * * Created on: 2013-10-8 * Author: wangzhu */ /** * 若n是偶数,且大于2,则输出YES, * 否则输出NO ...

  8. code forces Jeff and Periods

    /* * c.cpp * * Created on: 2013-10-7 * Author: wangzhu */ #include<cstdio> #include<iostrea ...

  9. Code Forces Gym 100971D Laying Cables(单调栈)

    D - Laying Cables Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u ...

随机推荐

  1. 基于centos7实现的nfs

    NFS NFS(Network FileSystem,网络文件系统),最早由Sun公司所发展出来的,主要是通过网络让不同的主机.不同的操作系统,可以彼此分享个别档案,因此我们也可以简单把NFS看成是一 ...

  2. php扩展开发-INI配置

    php.ini文件是用来保存各项扩展配置的文件,每个扩展都或多或少需要有一个定制化的配置,ini文件是一个很好的保存配置的方式,我们来看下怎么在自己的扩展里,使用到ini的配置功能 //创建ini的配 ...

  3. PHPExcel 中文使用手册详解

    /** * * execl数据导出 * 应用场景:订单导出 * @param string $title 模型名(如Member),用于导出生成文件名的前缀 * @param array $cellN ...

  4. Ubuntu下安装libpcap+测试安装

    1.从ftp://ftp.gnu.org/gnu/下载flex.bison.GNU M4.libpcap安装包,具体的链接分别如下: flex下载:http://flex.sourceforge.ne ...

  5. C语言数组篇(五)多级指针和二维数组指针的区别

    多级指针   以二级指针为例 二级指针的由来是 指针数组 的指针形式. int *p[10] 读取的顺序是 p[] --> 10个空间的数组 * p[] --> 这10个空间的数组里面存放 ...

  6. scrapy笔记2

    cookies的使用: 使用 scrapy.http.cookie.CookieJar 类的extract_cookies方法,CookieJar._cookies就是我们需要的cookies,是一个 ...

  7. POJ:3185-The Water Bowls(枚举反转)

    The Water Bowls Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7402 Accepted: 2927 Descr ...

  8. 3226: [Sdoi2008]校门外的区间

    链接 思路 bug漫天飞... 维护一颗线段树,支持区间赋值,和区间异或.因为会处理到一些方括号还是圆括号的问题,所以对于每一个下标都乘2,假设中间有一个.5即可,都变成了方括号,输出在处理一下. U ...

  9. 减少Android staido 占用C 盘

    1.gradle 更换文件夹: 设置GRADLE_USER_HOME环境变量 在/etc/profile或~/.bash_profile增加如下: export GRADLE_USER_HOME=D: ...

  10. myeclipse中项目名有红叉,但项目中文件没有报错的解决办法

    导入了别人的项目,各种jar包都放好后,path也都build好了,项目也能正常启动,但是就是项目名有红叉,这是为什么呢? 网上有人说Java build path中的jar包missing了,这是一 ...