#include<iostream>
#include"wz.h"
#include<ctime>
using namespace std;
#define MAX 5
void show(int arr[][MAX])
{
for(int i=0;i<MAX;i++)
{
for(int j=0;j<MAX;j++)
{
cout<<arr[i][j]<< " ";
}
cout<<endl;
}
cout<<endl;
}
void Change(int arr[][MAX],int x,int y)
{
if(x < 0 || y < 0 || x >= MAX || y >= MAX)
{
return ;
}
arr[x][y] = 1 -arr[x][y];
if(x-1 >= 0)
{
arr[x-1][y] = 1 - arr[x-1][y];
}
if(x+1 <= MAX)
{
arr[x+1][y] = 1 - arr[x+1][y];
}
if(y-1 >= 0)
{
arr[x][y-1] = 1 - arr[x][y-1];
}
if(y+1 <= MAX)
{
arr[x][y+1] = 1 - arr[x][y+1];
}
}
int man()
{
int arr[MAX][MAX] = {0};
int x;
int y;
int k=0;
time_t t;
srand((unsigned)time(&t));
k=rand()%5;
while(k--)
{
x=rand()%5;
y=rand()%5;
cout<<k<<x<<y<<endl;
arr[x][y]=1;
}
show(arr);
cout<<"熄灯前睡觉 输入坐标(x,y)"<<endl;
while( 1 )
{
cin>>x>>y;
x=x-1;y=y-1;
Change(arr,x,y);
show(arr);
}
}
int main()
{
int x= (int )time(NULL)%10;
cout<<x<<endl;
return 0;
}
#include"wz.h"
#include"sts.h"
#define MAX 5
void show(int arr[][MAX])
{
for(int i=0;i<MAX;i++)
{
for(int j=0;j<MAX;j++)
{
cout<<arr[i][j]<< " ";
}
cout<<endl;
}
cout<<endl;
}
void play(int arr[][MAX],int x,int y)
{
if(x < 0 || y < 0 || x >= MAX || y >= MAX)
{
return ;
}
arr[x][y] = 1 -arr[x][y];
if(x-1 >= 0)
{
arr[x-1][y] = 1 - arr[x-1][y];
}
if(x+1 < MAX)
{
arr[x+1][y] = 1 - arr[x+1][y];
}
if(y-1 >= 0)
{
arr[x][y-1] = 1 - arr[x][y-1];
}
if(y+1 < MAX)
{
arr[x][y+1] = 1 - arr[x][y+1];
}
}
void k1(int v[][MAX])
{
play(v,4,4); show(v); play(v,4,0); show(v);
play(v,2,4); show(v); play(v,2,0); show(v);
play(v,1,4); show(v); play(v,1,0); show(v);
play(v,1,3); show(v); play(v,1,1); show(v);
play(v,0,0); show(v); play(v,0,4); show(v);
}
void k2(int v[][MAX])
{
play(v,4,4); show(v); play(v,4,1); show(v);
play(v,4,0); show(v); play(v,3,4); show(v);
play(v,3,0); show(v); play(v,2,4); show(v);
play(v,2,2); show(v);
play(v,2,1); show(v); play(v,3,2); show(v);
play(v,4,4); show(v); play(v,1,2); show(v);
play(v,0,3); show(v); play(v,0,4); show(v);
}
void k3(int v[][MAX])
{
play(v,4,1); show(v); play(v,3,4); show(v);
play(v,3,3); show(v); play(v,3,1); show(v);
play(v,3,0); show(v); play(v,2,1); show(v);
play(v,2,0); show(v); play(v,1,4); show(v);
play(v,1,3); show(v); play(v,1,2); show(v);
play(v,2,0); show(v); play(v,0,3); show(v);
}
void k4(int v[][MAX])
{
play(v,4,3); show(v); play(v,4,1); show(v);
play(v,3,2); show(v); play(v,3,1); show(v);
play(v,2,4); show(v); play(v,2,3); show(v);
play(v,2,1); show(v); play(v,2,0); show(v);
play(v,1,4); show(v); play(v,1,1); show(v);
play(v,0,2); show(v); play(v,0,3); show(v);
play(v,2,3); show(v); play(v,3,3); show(v);
play(v,4,3); show(v); play(v,4,2); show(v);
}
void k5(int v[][MAX])
{
play(v,3,4); show(v); play(v,3,2); show(v);
play(v,3,1); show(v); play(v,3,0); show(v);
play(v,2,4); show(v); play(v,2,2); show(v);
play(v,2,1); show(v); play(v,1,4); show(v);
play(v,1,3); show(v); play(v,1,2); show(v);
play(v,1,1); show(v); play(v,1,0); show(v);
play(v,4,0); show(v); play(v,3,1); show(v);
play(v,2,1); show(v); play(v,0,1); show(v);
play(v,0,4); show(v); play(v,2,3); show(v);
play(v,4,3); show(v);
}
void cp(int v[][MAX])
{ int i,j;int k=0;
for(i=0;i<MAX-1;i++)
{
for(j=0;j<MAX;j++)
{
if(v[i][j]==1) play(v,i+1,j);
}
}
show(v);
i=MAX-1;
for(j=0;j<MAX;j++)
{
if(v[i][j]==1) k++;
}
if(k>0)
{
if((v[i][0]==v[i][4])&&(v[i][4]==1))k2(v);
if((v[i][2]==v[i][3])&&(v[i][3]==v[i][4]))k3(v);
if((v[i][0]==v[i][1])&&(v[i][1]==v[i][2]))k4(v);
if((v[i][1]==v[i][3])&&(v[i][3]==1))k5(v);
}
else cout<<"over"<<endl;
}
void cp2()
{
int v[MAX][MAX] = {0};
int i,j;
int x;
int y;
int k=0;
v[4][0]=1;
v[4][4]=1;
show(v);
k2(v);
}
void cp3()
{
int v[MAX][MAX] = {0};
v[4][2]=1;
v[4][3]=1;
v[4][4]=1;
show(v);
k3(v);
}
void cp4()
{
int v[MAX][MAX] = {0};
int i,j;
int x;
int y;
int k=0;
v[4][0]=1;
v[4][1]=1;
v[4][2]=1;
show(v);
k4(v);
}
void cp5()
{
int v[MAX][MAX] = {0};
int i,j;
int x;
int y;
int k=0;
v[4][1]=1;
v[4][3]=1;
show(v);
k5(v);
}
int player()
{
int v[MAX][MAX] = {0};
int x;
int y;
int k=3;
int state=1;
/* time_t t;
srand((unsigned)time(&t));
k=rand()%5+1;
while(k--)
{
x=rand()%5;
y=rand()%5;
v[x][y]=1;
}*/
v[4][2]=1;v[4][3]=1;v[4][4]=1;
show(v);
while( state)
{
//cout<<"输入0由电脑解答,1则继续"<<endl;
scanf("%d",&state);
if(state==1)cp(v);
// cout<<"熄灯前睡觉 输入坐标(x,y)"<<endl;
//cin>>x>>y; x=x-1;y=y-1;
//play(v,x,y); show(v);
}
}
int main()
{
cout<<" 欢迎参与点灯游戏 "<<endl<<" 由wzzx提供"<<endl;
cout<<" 游戏过程中可以选择电脑演示求解步骤 "<<endl;
cout<<"***************************************"<<endl;
player();
return 0;
}用了 测试的步骤模仿了玩法
当然 同一天已发现一个统一的秘密 可以在不用数学分析的方式来解决这个问题
原文:http://sts609.blog.51cto.com/11227442/1758684