Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard
AA AA
A A
A A
AA AAstruct point
{
int x;
int y;
}
bool IsRectangular(point *points, int num)
{
int left=0, right=0, top=0, bottom=0;
int num_top=0, num_bots=0, num_lefts=0, num_right=0;
// Find the dimensions
for(int i=0; i < num; ++i)
{
if(left > points[i].x)
left = points[i].x;
if(right < points[i].x)
right = points[i].x;
if(top > points[i].y)
top = points[i].y;
if(bottom < points[i].y)
bottom = points[i].y;
}
// Find residing sides of As
for(int i=0; i < num; ++i)
{
bool found = false;
if(points[i].x == left)
{
++num_lefts;
found = true;
}
if(points[i].x == right)
{
++num_right;
found = true;
}
if(points[i].y == top)
{
++num_tops;
found = true;
}
if(points[i].y == bottom)
{
++num_bots;
found = true;
}
if(!found) // Wasn't on the boundary as it should be
return false;
}
// Make sure the sides cancel out
if(num_top != num_bots || num_lefts != num_rights)
return false;
// Eliminate something like this:
// AAAA
// ABBA
// BBBB
// AAAA
if(bottom-top != num_lefts+2 || right-left != num_tops+2)
return false;
return true;
}
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
int j,i=0,c=0,Count;
bool a=false;
char mat[6][12]={"AAAAAAAABBB",
"ABBAABBABBB",
"ABBBABBABBB",//To be more clear
"ABBBABBBBBB",
"AAABABBBBBB",
"AAAAABBBBBB"};
for(i,cout<<'\t';i<6;cout<<'\n'<<'\t',++i)
for(j^=j;j<11;cout<<mat[i][j],++j){}//Output the original matrix
for(c;a==false;c++){
a=true;
for(i^=i;i<6;i++)
for(j^=j;j<11;j++){
if(mat[i][j]=='A'){
Count=0;
if(i>0)if(mat[i-1][j]=='A')Count++;
if(i<5)if(mat[i+1][j]=='A')Count++;
if(j>0)if(mat[i][j-1]=='A')Count++;
if(j<10)if(mat[i][j+1]=='A')Count++;
if(Count<2){mat[i][j]=' ';a=false;}//Change here,to leave
} //the "wrong" 'A'
else mat[i][j]=' ';//Delete the 'else' to leave the original matrix
}
}
cout<<'\n'<<"---> After "<<c<<" cycles : "<<endl;
for(i^=i,cout<<'\n'<<'\t';i<6;cout<<'\n'<<'\t',++i)
for(j^=j;j<11;cout<<mat[i][j],++j){}//Output the modified matrix
cout<<'\n';
system("pause");
return 0;
}#include <stdio.h>
char*_="XxTIHRCXCxTIHRXRCxTIHXHRCxTIXIHRCxTXTIHRCxXxTIHRCX";
int main(int l){for(l+=7;l!=putchar(010);++l);if(*(++_))main
(*_!=88?(putchar(*_^073)|putchar(33))&1:0xffff2a8b);}Return to Algorithms & Data Structures
Users browsing this forum: Google Adsense [Bot] and 4 guests