标签:def 暴力求解 class += pac clu span als div
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct point{
int x;int y;
}sq[4],sp[4];
bool cmp(point a,point b){
if(a.x == b.x) return a.y < b.y;
return a.x < b.x;
}
//t[i][j]=1表示第一个正方形包含这个点。
int t[220][220];
void tian(point a,point b){
for(int i = a.x;i <= b.x; ++i){
for(int j = a.y;j <= b.y; ++j){
t[i][j] = 1;
}
}
}
//判断第二个正方形是否包含t[i][j]为1的点(i,j)
bool judge(point* sp){
for(int i = sp[0].x;i <= sp[1].x; ++i){
for(int j = 0;j <= i-sp[0].x; ++j){
if(t[i][sp[0].y+j] == 1 or t[i][sp[0].y-j] == 1){
return true;
}
}
}
for(int i = sp[1].x;i <= sp[3].x; ++i){
for(int j = 0;j <= sp[2].y-sp[0].y-(i-sp[1].x); ++j){
if(t[i][sp[0].y+j] == 1 or t[i][sp[0].y-j] == 1){
return true;
}
}
}
return false;
}
int main(){
for(int i = 0;i < 4; ++i) cin >> sq[i].x >> sq[i].y, sq[i].x+=100,sq[i].y+=100;
for(int i = 0;i < 4; ++i) cin >> sp[i].x >> sp[i].y, sp[i].x+=100,sp[i].y+=100;
sort(sq,sq+4,cmp);
sort(sp,sp+4,cmp);
tian(sq[0],sq[3]);
if(judge(sp)) cout << "YES" << endl;
else cout << "NO" << endl;
return 0;
}
Codeforces 993A. Two Squares(暴力求解)
标签:def 暴力求解 class += pac clu span als div
原文地址:https://www.cnblogs.com/zhangjiuding/p/9192583.html