1. 程式人生 > 其它 >Codeforces Round #777 (Div. 2) B. Madoka and the Elegant Gift

Codeforces Round #777 (Div. 2) B. Madoka and the Elegant Gift

 

 【題目大意】:

  如果任意兩個最大矩形不相交則輸出YES,否則輸出NO。

【思路】:

  資料範圍比較小,100*100.所以可以暴力遍歷。

  找到最大矩形相交   ---------   不能出現【俄羅斯方塊中的L形】 , 例如一個點右邊下邊都是1 但是右下角是0 就不行。 所以是任意點的右,下,右下中不能有三個是1,一個是0。這樣就會形成兩個矩形。

【程式碼】:

 1 #include <bits/stdc++.h>
 2 #include <iostream>
 3 #include <cstdio>
 4 #include <cstring>
 5
#include <algorithm> 6 #include <string> 7 #include <vector> 8 #include <stack> 9 #include <bitset> 10 #include <cstdlib> 11 #include <cmath> 12 #include <set> 13 14 #define ms(a, b) memset(a,b,sizeof(a)) 15 #define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) 16
#define ll long long 17 #define ull unsigned long long 18 #define rep(i, a, b) for(ll i=a;i<=b;i++) 19 #define lep(i, a, b) for(ll i=a;i>=b;i--) 20 #define endl '\n' 21 #define pii pair<int, int> 22 #define pll pair<ll, ll> 23 #define vi vector<ll> 24 #define vpi vector<pii> 25
#define vpl vector<pll> 26 #define mi map<ll,ll> 27 #define all(a) (a).begin(),(a).end() 28 #define gcd __gcd 29 #define pb push_back 30 #define mp make_pair 31 #define lb lower_bound 32 #define ub upper_bound 33 34 #define ff first 35 #define ss second 36 #define test4(x, y, z, a) cout<<"x is "<<x<<" y is "<<y<<" z is "<<z<<" a is "<<a<<endl; 37 #define test3(x, y, z) cout<<"x is "<<x<<" y is "<<y<<" z is "<<z<<endl; 38 #define test2(x, y) cout<<"x is "<<x<<" y is "<<y<<endl; 39 #define test1(x) cout<<"x is "<<x<<endl; 40 using namespace std; 41 const int N =150; 42 const int maxx = 0x3f3f3f; 43 const int mod = 1e9 + 7; 44 const int minn = -0x3f3f3f; 45 const int M = 2 * N; 46 ll T, n, m; 47 char s[N][M]; 48 int a[N][M]; 49 int flag1[N][M],flag2[N][M]; 50 void solve() { 51 cin>>n>>m; 52 rep(i,1,n){ 53 rep(j,1,m){ 54 cin>>s[i][j]; 55 a[i][j]= s[i][j]-'0'; 56 } 57 } 58 rep(i,1,n-1){ 59 rep(j,1,m-1){ 60 if ( a[i][j]+a[i+1][j]+a[i][j+1]+a[i+1][j+1] == 3 ) {cout<<"NO"<<endl;return ;} 61 } 62 } 63 cout<<"YES"<<endl;return ; 64 } 65 66 int main() { 67 fast; 68 cin >> T; 69 while (T--) { 70 solve(); 71 } 72 return 0; 73 }
View Code