codeforces 994C Two Squares暴力

该博客介绍了如何判断两个正方形是否相交,其中一个正方形与坐标轴平行,另一个与坐标轴成45度角。输入包含两个正方形的四个顶点坐标,通过暴力遍历方法检查每个点是否在另一个正方形内来确定相交情况。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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
and 100

.
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:

Codeforces © Copyright 2010-2018 Mike Mirzayanov

题意:两行,每行给出4组坐标,表示一个正方形,第一行的正方形①与x轴平行,第二行的正方形②与x轴成45度角,问,这两个正方形是否相交。(哪怕只有一个点重合也是相交)

暴力,类似与当初打印菱形的那种,便历其中一个菱形中的每一个点,看他是否在另一个菱形中,因为我不会表示一条倾斜的边,所以只能用这种笨办法。

#include <bits/stdc++.h>
using namespace std;
int main(){
    int flag = 0,mx,my,mxx2 = -105,mxy2 = -105,mix2 = 121,miy2 = 112;
    int x,y,mxx1 = -105,mxy1 = -105,mix1 = 121,miy1 = 121;
    for(int i = 0;i < 4;i++)
    {
        cin>>x>>y;
        mxx1 = max(mxx1,x);
        mxy1 = max(mxy1,y);
        mix1 = min(mix1,x);
        miy1 = min(miy1,y);

    }
    /* for(int  i = mix1;i <= mxx1 ;i++) */
    /* { */
    /*     for(int j = miy1;j <= mxy1;j++) */
    /*     { */
    /*         printf("%d %d",i,j); */
    /*     } */
    /*     putchar('\n'); */
    /* } */
    for(int i = 0;i < 4;i++)
    {
        cin>>x>>y;
        mxx2 = max(mxx2,x);
        mxy2 = max(mxy2,y);
        mix2 = min(mix2,x);
        miy2 = min(miy2,y);

    }
    int h = (mxx2-mix2)/2;
    int hh = h,yy = 0;
    //printf("mix2=%d mxx2=%d miy2=%d mxy2=%d\n",mix2,mxx2,miy2,mxy2);
    
    for(int i = mix2;i <= mxx2;i++)
    {   
        if(h>0){
            for(int j = miy2 + h;j <= mxy2 - h;j++)
            {
                if(i <= mxx1&&i >= mix1 && j <= mxy1 && j >= miy1)
                {
                    flag = 1;
                    break;
                }
                //printf("\ni=%d,j=%d\n",i,j);
            }
            h--;
        }
        else{
            for(int j = miy2 + yy;j <= mxy2 - yy;j++)
            {
                if(i <= mxx1&&i >= mix1 && j <= mxy1 && j >= miy1)
                {
                    flag = 1;
                    break;
                }
                //printf("\ni=%d,j=%d\n",i,j);
            }
            yy++;
        }

    }
    if(flag == 1)
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Randy__Lambert

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值