codeforces 994C Two Squares暴力

    xiaoxiao2022-07-04  120

    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; }
    最新回复(0)