Transformations

本文介绍了一种通过旋转和反射操作来识别图案转换的算法。该算法可以判断原始图案经过90度、180度、270度旋转或水平翻转等变化后是否能与目标图案匹配。

题目描述:

A square pattern of size N x N (1 <= N <= 10) black and white square tiles is transformed into another square pattern. Write a program that will recognize the minimum transformation that has been applied to the original pattern given the following list of possible transformations:

  • #1: 90 Degree Rotation: The pattern was rotated clockwise 90 degrees.
  • #2: 180 Degree Rotation: The pattern was rotated clockwise 180 degrees.
  • #3: 270 Degree Rotation: The pattern was rotated clockwise 270 degrees.
  • #4: Reflection: The pattern was reflected horizontally (turned into a mirror image of itself by reflecting around a vertical line in the middle of the image).
  • #5: Combination: The pattern was reflected horizontally and then subjected to one of the rotations (#1-#3).
  • #6: No Change: The original pattern was not changed.
  • #7: Invalid Transformation: The new pattern was not obtained by any of the above methods.

In the case that more than one transform could have been used, choose the one with the minimum number above.

输入输出格式:

SAMPLE INPUT (file transform.in)

3
@-@
---
@@-
@-@
@--
--@

OUTPUT FORMAT

A single line containing the number from 1 through 7 (described above) that categorizes the transformation required to change from the `before' representation to the `after' representation.

SAMPLE OUTPUT (file transform.out)

1

题目大意:

题意:给定一个字符串方块和目标字符串方块。 
90度顺时针旋转 
2: 180度顺时针旋转 
3: 270度顺时针旋转 
4: 以中心轴为轴翻转 
5: 以中心轴为轴翻转后进行1-3种中任意一种操作 
6: 不变 
7: 不能转换过去 
问通过这些操作中的任意一个操作是否能够由给定字符串方块转换到目标字符串方块。如果多种操作都可以,那么输出编号最小的操作的编号。
解题思路:

其实是一个水题,就是列举出所有可能性,然后一个一个试出来就行,这里介绍两个函数void *memset(void *s, int ch, size_t n);函数解释:将s中当前位置后面的n个字节 (typedef unsigned int size_t )用 ch 替换并返回 s 。memset:作用是在一段内存块中填充某个给定的值,它是进行清零操作的一种最快方法,void* memcpy(void* destination, const void* source, size_t num);
void* dest 目标内存    const void* src  源内存    size_t num  字节个数,代码如下

#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <map>
#include <cstdio>
#include <algorithm>
#define N 20
using namespace std;
int n;
char s[N][N], r[N][N];
void Rotation(){
	char temp[N][N];
	memset(temp,'\0',sizeof(temp));
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++){
			temp[i][j]=s[n-1-j][i];
		}
	memcpy(s,temp,sizeof(temp));
}
void reflected(){
	for(int i=0;i<n;i++){
		for(int j=0;j<n/2;j++){
			swap(s[i][j],s[i][n-1-j]);
		}
	}
}
bool check(){
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(s[i][j]!=r[i][j])
				return false;
		}
	}
	return true;
}
bool option(int op){
	if(op==1)
		Rotation();
	else if(op==2)
		Rotation();
	else if(op==3)
		Rotation();
	else if(op==4){
		Rotation();//要转回去
		reflected();
	}
	else if(op==5){
		for(int i=0;i<3;i++){
			Rotation();
			if(check()){
				return true;
			}
		}
		return false;
	}
	else if(op==6){
		Rotation();
		reflected();
	}
	return check();
}
int main(){
	int choose;
	freopen("D:\\test.in","r",stdin);
	freopen("D:\\transform1.out","w",stdout);
	scanf("%d",&n);
	memset(s,'\0',sizeof(s));
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			cin>>s[i][j];
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			cin>>r[i][j];
	for(choose=1;choose<7;choose++){
		if(option(choose)){
			printf("%d\n",choose);
			break;
		}
	}
	if(choose==7){
		printf("%d\n",7);
	}
	return 0;
}

 

基于径向基函数神经网络RBFNN的自适应滑模控制学习(Matlab代码实现)内容概要:本文介绍了基于径向基函数神经网络(RBFNN)的自适应滑模控制方法,并提供了相应的Matlab代码实现。该方法结合了RBF神经网络的非线性逼近能力和滑模控制的强鲁棒性,用于解决复杂系统的控制问题,尤其适用于存在不确定性和外部干扰的动态系统。文中详细阐述了控制算法的设计思路、RBFNN的结构与权重更新机制、滑模面的构建以及自适应律的推导过程,并通过Matlab仿真验证了所提方法的有效性和稳定性。此外,文档还列举了大量相关的科研方向和技术应用,涵盖智能优化算法、机器学习、电力系统、路径规划等多个领域,展示了该技术的广泛应用前景。; 适合人群:具备一定自动控制理论基础和Matlab编程能力的研究生、科研人员及工程技术人员,特别是从事智能控制、非线性系统控制及相关领域的研究人员; 使用场景及目标:①学习和掌握RBF神经网络与滑模控制相结合的自适应控制策略设计方法;②应用于电机控制、机器人轨迹跟踪、电力电子系统等存在模型不确定性或外界扰动的实际控制系统中,提升控制精度与鲁棒性; 阅读建议:建议读者结合提供的Matlab代码进行仿真实践,深入理解算法实现细节,同时可参考文中提及的相关技术方向拓展研究思路,注重理论分析与仿真验证相结合。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值