star

搜索

RSS

RSS Link

计数器

133481
曼德勃罗特集
数据结构头文件Ver1.0

迷你小游戏

Star posted @ 2010年8月21日 03:46 in C语言 with tags c 搜索 , 2346 阅读
#include <stdio.h>
#define MAXLEN 10	//最大8*8阵 
#defint MAXSTEP 100 //最多100步 
int DesMar[MAXLEN][MAXLEN];//目标矩阵 
int SrcMar[MAXLEN][MAXLEN];//原矩阵 
int N, NeedTimes;//矩阵大小和需要次数
struct pos {int x, y;}res[MAXSTEP];//解 

void TurnMar(int x, int y)//转一下 
{
	int i, j;
	for(i = x-1; i <= x+1; ++i)
		for(j = y-1; j <= y+1; ++j)
			SrcMar[i][j] ^= 1;
}

int Checked()//检查是否为解 
{
	int i, j;
	for(i = 1; i <= N; ++i)
		for(j = 1; j <= N; ++j)
			if(SrcMar[i][j] != DesMar[i][j])
				return 0;
	return 1;
}

int DFS(int n)//搜索 
{
	int i, j;
	if(n >= NeedTimes)
		if(Checked())
			return 1;
		else
			return 0;
	for(i = 1; i <= N; ++i)
		for(j = 1; j <= N; ++j)
		{
			TurnMar(i, j);
			res[n].x = i, res[n].y = j;
			if(!DFS(n+1))
				TurnMar(i, j);
			else
				return 1;
		}
	return 0;
}

int main(void)
{
	int i, j;
	while(scanf("%d", &N),N)//输入0退出程序 
	{
		puts("input the source info:");
		for(i = 1; i <= N; ++i)//输入原矩阵信息 
			for(j = 1; j <= N; ++j)
				scanf("%d", &SrcMar[i][j]);
		puts("input the destination info:");
		for(i = 1; i <= N; ++i)//输入目标矩阵信息 
			for(j = 1; j <= N; ++j)
				scanf("%d", &DesMar[i][j]);
		puts("input the times:");//输入次数 
		scanf("%d", &NeedTimes);

		DFS(0);

		for(i = 0; i < NeedTimes; ++i)
			printf("%d %d\n", res[i].x, res[i].y);
	}
	return 0;
}
wuxiaworld 说:
2019年6月01日 18:03

The information you have posted is very useful. The sites you have referred was good. Thanks for sharing

TN 12th Question Pap 说:
2021年9月28日 19:40

Students can get the TN 12th Model Question Paper 2022 with Solutions in PDF format from the links provided on this website. (+2) HSC Regular and private students can use these Sample Papers to prepare for their exams. Students must register for the Public Exam 2022. TN 12th Question Paper If you are one of the students who has registered as a Regular or Private Student, it is recommended that you download these Tamil Nadu Board Plus Two Sample Paper 2022 and prepare all subjects. Model papers are a valuable resource provided by the recognised educational board.

192.168.1.1 router l 说:
2023年2月08日 15:33

Do you own a router or modem, then you might have heard about the term Internal configuration and router configuration which are very important to do when you first buy a new router or when you have just reset a router. 192.168.1.1 router login Frankly speaking, there are hundreds of router brands across the world and every one of them has high end router models that have a different configuration process.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter