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. python数据类型的转换

  2. PHP使用redis(一)

    1,connect 描述:实例连接到一个Redis.参数:host: string,port: int返回值:BOOL 成功返回:TRUE;失败返回:FALSE <?php  $redis = ...

  3. 简单的for循环实现九九乘法表

    PHP for 循环 语法 for (init counter; test counter; increment counter) { code to be executed; } 参数: init ...

  4. yii2 的登录注册 轮子

    //利用到了yii2 框架之中的验证规则 进行判定而已 也不是很高深的东西  但是 使用框架自身的轮子 会有安全性能的隐患 1注册reg controller 中 我都以admin 为例子 publi ...

  5. 小白对异步IO的理解

    前言 看到越来越多的大佬都在使用python的异步IO,协程等概念来实现高效的IO处理过程,可是我对这些概念还不太懂,就学习了一下. 因为是初学者,在理解上有很多不到位的地方,如果有错误,还希望能够有 ...

  6. Linux之rsync同步工具介绍+inotify同步

    1.rsync介绍 Rsync是一款开源的.快速的.多功能的.可实现全量及增量的本地或远程数据同步备份的优秀工具.Rsync软件适用于unix/linux/windows等多种操作平台. rsync, ...

  7. 使用dataframe解决spark TopN问题:分组、排序、取TopN和join相关问题

    package com.profile.mainimport org.apache.spark.sql.expressions.Windowimport org.apache.spark.sql.fu ...

  8. Python 文本挖掘:使用情感词典进行情感分析(算法及程序设计)

    出处:http://www.ithao123.cn/content-242299.html 情感分析就是分析一句话说得是很主观还是客观描述,分析这句话表达的是积极的情绪还是消极的情绪.   原理 比如 ...

  9. 01,jupyter环境安装

    jupyter notebook环境安装 一.什么是Jupyter Notebook? 1. 简介 Jupyter Notebook是基于网页的用于交互计算的应用程序.其可被应用于全过程计算:开发.文 ...

  10. ios交叉编译dylib

    ios交叉编译dylib 因多个静态库,libes,libffmpeg,libmt. libpcap 使用不方便 在封装一层接口,生成动态库(c代码),由IOS app上层调用. IOS_BASE_S ...