Translate

Views

Monday, July 29, 2019

Solution Kattis: 10 Kinds of People

https://open.kattis.com/problems/10kindsofpeople
#include<bits/stdc++.h>
#define FOR(i, a, b) for(int i=a; i<=b; i++)
#define N 1001
using namespace std;

int n, m, q, bi, bj, ei, ej, cl;
char a[N][N];
int color[N][N];
int h[4]={1,-1,0,0};
int c[4]={0,0,-1,1};

void flood_fill(int i, int j, int cl){
 FOR(k, 0 ,3){
  int ii=i+h[k];
  int jj=j+c[k];
  
  if (ii>=0 && ii<=n && jj>=0 && jj<=m)
  if (color[ii][jj]==0 && a[ii][jj]==a[i][j]){
   color[ii][jj]=cl;
   flood_fill(ii, jj, cl);
  }
 } 
}

int main(){  
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
 
 cin >> n >> m;
 FOR(i, 1, n) FOR(j, 1, m) cin >> a[i][j];
 
 FOR(i, 1, n) FOR(j, 1, m) 
 if (color[i][j]==0){
  cl++;
  color[i][j]=cl;
  flood_fill(i,j,cl); 
 } 
 
 cin >> q;
 FOR(i, 1, q){
  cin >> bi >> bj >> ei >> ej;
  
  if (color[bi][bj]!=color[ei][ej]) 
                    cout<<"neither\n";
  else 
  if (a[bi][bj]=='1') cout<<"decimal\n"; 
                    else cout<<"binary\n"; 
 }
}
Good luck! If you need help please leave a comment :) 

No comments: