D floor solution
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<stdio.h>
using namespace std;
char cmp(char s)
{
if (s=='0')
return '1';
else if(s=='1')
return '0';
}
/* Main code starts from here */
int main()
{
vector<vector<char> > m(16,vector<char>(16));
vector<int> arr1(226);
vector<int> arr2(226);
int i,j,x,y;
while(1)
{
cin>>x>>y;
if(x==0 &&y==0)
return 0;
for(i=0;i<y;i++)
{
for(j=0;j<x;j++)
{
cin>>m[i][j];
}
}
int k=0 ,flag=0;
for(i=1;i<y;i++)
{
for(j=0;j<x;j++)
{
if(m[i-1][j]=='0')
{
m[i][j]=cmp(m[i][j]);
if((i-1)>=0)
m[i-1][j]=cmp(m[i-1][j]);
if((j+1)<=x)
m[i][j+1]=cmp(m[i][j+1]);
if((i+1)<=y)
m[i+1][j]=cmp(m[i+1][j]);
if((j-1)>=0)
m[i][j-1]=cmp(m[i][j-1]);
k++;
arr1[k]=i+1;
arr2[k]=j+1;
}
}
}
for(i=1;i<y;i++)
{
for(j=0;j<x;j++)
{
if(m[i][j]=='0')
flag=1;
}
}
if(flag==1)
cout<<"-1"<<endl;
else
{
cout<<k<<endl;
for(i=1;i<=k;i++)
{
cout<<arr2[i]<<" "<<arr1[i]<<endl;
}
}
cout<<endl;
}
return 0;
}
On 8/23/11, Piyush Kapoor <[email protected]> wrote:
> For Dance Floor:
> 1)Note that the order in which you tap tiles is unimportant.
> 2)Try all subsets(or combinations) of tapping tiles on the first row,then in
> the other rows we only need to tap when the tile directly above is not lit.
> 3)Base condition will be when you finish with the last row,then the check if
> the last row contains all lit ones..
>
> On Tue, Aug 23, 2011 at 4:47 AM, Victor Manuel Grijalva Altamirano <
> [email protected]> wrote:
>
>> I am trying the problem http://www.spoj.pl/problems/CERC07B/ and
>> http://www.spoj.pl/problems/DFLOOR/ but i don“t have idea how to solve,
>> anyone can help me???
>>
>> --
>> Victor Manuel Grijalva Altamirano
>> Universidad Tecnologica de La Mixteca
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> *Regards,*
> *Piyush Kapoor,*
> *2nd year,CSE
> IT-BHU*
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>
--
*Anil Arya,
Computer Science *
*Motilal Nehru National Institute of Technology,Allahabad .
*
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.