Skip to content

Instantly share code, notes, and snippets.

@kusano
Created January 18, 2019 04:16
Show Gist options
  • Save kusano/421ba9f3215adaf8b82ed552b5102208 to your computer and use it in GitHub Desktop.
Save kusano/421ba9f3215adaf8b82ed552b5102208 to your computer and use it in GitHub Desktop.
#include <string>
#include <vector>
using namespace std;
class SpecificPolyominoCovering{public:
vector <string> findCovering( vector <string> region )
{
int w = (int)region[0].size();
int h = (int)region.size();
for (int y=0; y<h; y++)
for (int x=0; x<w; x++)
{
if (region[y][x]=='X')
{
if (x+1<w && region[y][x+1]=='X')
{
region[y][x] = '[';
region[y][x+1] = ']';
}
else if (x+3<w && y+1<h &&
region[y][x+3]=='X' &&
region[y+1][x]=='X' &&
region[y+1][x+1]=='X' &&
region[y+1][x+2]=='X' &&
region[y+1][x+3]=='X')
{
region[y][x] = 'A';
region[y][x+3] = 'A';
region[y+1][x] = 'A';
region[y+1][x+1] = 'A';
region[y+1][x+2] = 'A';
region[y+1][x+3] = 'A';
}
else
return vector<string>();
}
}
for (int y=0; y+1<h; y++)
for (int x=0; x+3<w; x++)
{
if (region[y ][x ]=='[' && region[y ][x+1]==']' &&
region[y ][x+2]=='[' && region[y ][x+3]==']' &&
region[y+1][x ]=='[' && region[y ][x+1]==']' &&
region[y+1][x+2]=='[' && region[y ][x+3]==']')
{
region[y ][x ] = 'A';
region[y ][x+1] = 'B';
region[y ][x+2] = 'B';
region[y ][x+3] = 'A';
region[y+1][x ] = 'A';
region[y+1][x+1] = 'A';
region[y+1][x+2] = 'A';
region[y+1][x+3] = 'A';
}
}
for (int y=0; y<h; y++)
for (int x=0; x<w; x++)
if (region[y][x]=='[' || region[y][x]==']')
region[y][x] = 'B';
return region;
}};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment