Codeforces 993A. Two Squares(暴力求解)
生活随笔
收集整理的這篇文章主要介紹了
Codeforces 993A. Two Squares(暴力求解)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
解題思路(暴力解法)
代碼
#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(暴力求解)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Codeforces 994B. Kni
- 下一篇: Codeforces 993C. Car