习题7-16(uva-11846)

本文介绍了一种解决填字游戏问题的算法实现,通过深度优先搜索和回溯技术来寻找最优解。文章详细展示了如何处理游戏矩阵,利用递归方法进行搜索,并考虑了数字与字母区域的有效分配。
#include <iostream>
#include <istream>
#include <sstream>
#include <vector>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <chrono>
#include <ctime>
#include <cmath>
#include <cctype>
#include <string>
#include <cstdio>
#include <iomanip>


#include <thread>
#include <mutex>
#include <condition_variable>
#include <functional>
#include <iterator>
using namespace std;
const int maxn = 25;
char matrix[maxn][maxn], ans[maxn][maxn];
int n, k;

int GetGroupCnt(int l, int t, int r, int d) {
	int cnt = 0,ret = 0;
	for (int i = l; i <= r; i++) {
		for (int j = t; j <= d; j++) {
			if (isdigit(matrix[i][j])){
				ret = matrix[i][j] - '0';
				if (++cnt > 1) return -cnt;
			}
		}
	}
	return ret;
}

void FillAns(int l, int t, int r, int d,char value) {
	for (int i = l; i <= r; i++) {
		for (int j = t; j <= d; j++) {
			ans[i][j] = value;
		}
	}
}

bool dfs(int index, char id) {
	//index一维的下标转化为二维下标  找空闲的
	while (ans[index / n][index % n] != '.') ++index;

	if (index == n * n) return true;

	//确定左上角坐标 x y
	int lx = index / n, ly = index % n,rBound = n,isover = 0;

	//找右下角坐标
	for (int rx = lx; rx < n; rx++) {
		for (int ry = ly; ry < rBound; ry++) {
			//向右扩展失败 当前已被填充 收缩右部
			if (ans[rx][ry] != '.') { rBound = ry;break; }
			//计算容量的人数
			int tot = (ry - ly + 1) * (rx - lx + 1);
			//太大了 人家不想要
			if (tot > 9) { rBound = ry; break; }
			//查看当前矩形局域是否只有一个小组且容量够
			int cnt = GetGroupCnt(lx, ly, rx, ry);
			
			//找到多个小组收缩 或者容量大了 
			if (cnt < 0 || (cnt > 0 &&  cnt < tot )) {
				//收缩右部
				rBound = ry;
				break;
			}

			//容量不够 继续扩展 或者一个都没有
			if(cnt > tot || cnt == 0) continue;

			//尝试填充
			FillAns(lx, ly, rx, ry, id);
			//能够找到解决方案就不回溯
			if (dfs(index, id + 1)) return true;
			//不行啊
			FillAns(lx, ly, rx, ry, '.');
		}
	}
	return false;
}

int main()
{
	while (cin >> n >> k && n && k) {
		memset(ans, '.', sizeof(ans));

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				cin >> matrix[i][j];
			}
		}
		dfs(0, 'A');
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				cout << ans[i][j];
			}
			cout << endl;
		}
	}

	return 0;
}
演示了为无线无人机电池充电设计的感应电力传输(IPT)系统 Dynamic Wireless Charging for (UAV) using Inductive Coupling 模拟了为无人机(UAV)量身定制的无线电力传输(WPT)系统。该模型演示了直流电到高频交流电的转换,通过磁共振在气隙中无线传输能量,以及整流回直流电用于电池充电。 系统拓扑包括: 输入级:使用IGBT/二极管开关连接到全桥逆变器的直流电压源(12V)。 开关控制:脉冲发生器以85 kHz(周期:1/85000秒)的开关频率运行,这是SAE J2954无线充电标准的标准频率。 耦合级:使用互感和线性变压器块来模拟具有特定耦合系数的发射(Tx)和接收(Rx)线圈。 补偿:包括串联RLC分支,用于模拟谐振补偿网络(将线圈调谐到谐振频率)。 输出级:桥式整流器(基于二极管),用于将高频交流电转换回直流电,以供负载使用。 仪器:使用示波器块进行全面的电压和电流测量,用于分析输入/输出波形和效率。 模拟详细信息: 求解器:离散Tustin/向后Euler(通过powergui)。 采样时间:50e-6秒。 4.主要特点 高频逆变:模拟85 kHz下IGBT的开关瞬态。 磁耦合:模拟无人机着陆垫和机载接收器之间的松耦合行为。 Power GUI集成:用于专用电力系统离散仿真的设置。 波形分析:预配置的范围,用于查看逆变器输出电压、初级/次级电流和整流直流电压。 5.安装与使用 确保您已安装MATLAB和Simulink。 所需工具箱:必须安装Simscape Electrical(以前称为SimPowerSystems)工具箱才能运行sps_lib块。 打开文件并运行模拟。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值