20240814

news/2024/11/17 12:58:05/文章来源:https://www.cnblogs.com/libohan/p/18426823

Sternhalma

我们给格子编个号,然后暴力打表出一个格子可以走到哪些点,然后状压 \(dp\),从全 \(1\) 的情况开始倒推,每次查询将其转化为二进制数列即可

#include <bits/stdc++.h>using namespace std;using pii = pair<int, int>;const int N = 21, M = (1 << 19);int q, n, a[N][N], len[] = {0, 3, 4, 5, 4, 3}, dp[N][M];vector<int> road1[N];vector<int> road2[N];char x[N][N];vector<int> v[21];bool check(int x, int y) {if (x < 1 || x > 5 || y < 1 || y > len[x]) {return false;}return true;
}int change(int x, int y) {int ans = 0;for (int i = 1; i < x; i++) {ans += len[i];}return ans + y;
}pii one_to_two(int x) {for (int i = 1; i <= 5; i++) {if (x <= len[i]) {return {i, x};}x -= len[i];}
}void Solve() {int cnt = 0, res = 0;for (int i = 1; i <= 5; i++) {for (int j = 1; j <= len[i]; j++) {cin >> x[i][j];cnt += (x[i][j] == '#');res += (1 << (change(i, j) - 1)) * (x[i][j] == '#');}}cout << dp[cnt][res] << "\n";
}int main() {ios::sync_with_stdio(0);cin.tie(0);for (int i = 0; i <= (1 << 19) - 1; i++) {int p = i, cnt = 0;while (p) {cnt += (p & 1);p >>= 1;}v[cnt].push_back(i);}road1[1].push_back(2), road1[1].push_back(4), road1[1].push_back(5);road2[1].push_back(3), road2[1].push_back(8), road2[1].push_back(10);road1[2].push_back(5), road1[2].push_back(6);road2[2].push_back(9), road2[2].push_back(11);roa d1[3].push_back(2), road1[3].push_back(6), road1[3].push_back(7);road2[3].push_back(1), road2[3].push_back(10), road2[3].push_back(12);road1[4].push_back(5), road1[4].push_back(9);road2[4].push_back(6), road2[4].push_back(14);road1[5].push_back(6), road1[5].push_back(10), road1[5].push_back(9);road2[5].push_back(7), road2[5].push_back(15), road2[5].push_back(13);road1[6].push_back(5), road1[6].push_back(10), road1[6].push_back(11);road2[6].push_back(4), road2[6].push_back(14), road2[6].push_back(16);road1[7].push_back(6), road1[7].push_back(11);road2[7].push_back(5), road2[7].push_back(15);road1[8].push_back(4), road1[8].push_back(9), road1[8].push_back(13);road2[8].push_back(1), road2[8].push_back(10), road2[8].push_back(17);road1[9].push_back(5), road1[9].push_back(10), road1[9].push_back(14);road2[9].push_back(2), road2[9].push_back(11), road2[9].push_back(18);road1[10].push_back(5), road1[10].push_back(6), road1[10].push_back(11);road2[10].push_back(1), road2[10].push_back(3), road2[10].push_back(12);road1[10].push_back(15), road1[10].push_back(14), road1[10].push_back(9);road2[10].push_back(19), road2[10].push_back(17), road2[10].push_back(8);road1[11].push_back(6), road1[11].push_back(10), road1[11].push_back(15);road2[11].push_back(2), road2[11].push_back(9), road2[11].push_back(18);road1[12].push_back(7), road1[12].push_back(11), road1[12].push_back(16);road2[12].push_back(3), road2[12].push_back(10), road2[12].push_back(19);road1[13].push_back(9), road1[13].push_back(14);road2[13].push_back(5), road2[13].push_back(15);road1[14].push_back(9), road1[14].push_back(10), road1[14].push_back(15);road2[14].push_back(4), road2[14].push_back(6), road2[14].push_back(16);road1[15].push_back(11), road1[15].push_back(10), road1[15].push_back(14);road2[15].push_back(7), road2[15].push_back(5), road2[15].push_back(13);road1[16].push_back(11), road1[16].push_back(15);road2[16].push_back(6), road2[16].push_back(14);road1[17].push_back(13), road1[17].push_back(14), road1[17].push_back(18);road2[17].push_back(8), road2[17].push_back(10), road2[17].push_back(19);road1[18].push_back(14), road1[18].push_back(15);road2[18].push_back(9), road2[18].push_back(11);road1[19].push_back(16), road1[19].push_back(15), road1[19].push_back(18);road2[19].push_back(12), road2[19].push_back(10), road2[19].push_back(17);for (int i = 1; i <= 5; i++) {for (int j = 1; j <= len[i]; j++) {cin >> a[i][j];}}memset(dp, 0xcf, sizeof(dp));dp[0][0] = 0;for (int i = 0; i < 19; i++) {for (auto j : v[i]) {for (int x = 1; x <= 19; x++) {if ((j & (1 << (x - 1)))) {continue;}dp[i + 1][j + (1 << (x - 1))] = max(dp[i + 1][j + (1 << (x - 1))], dp[i][j]);for (int l = 0; l < road1[x].size(); l++) {int tot1 = (1 << (road1[x][l] - 1));int tot2 = (1 << (road2[x][l] - 1));if (!(j & tot1) && (j & tot2)) {dp[i + 1][(j + tot1 + (1 << (x - 1))) - tot2] = max(dp[i + 1][(j + tot1 + (1 << (x - 1))) - tot2], dp[i][j] + a[one_to_two(road1[x][l]).first][one_to_two(road1[x][l]).second]);}}}}}cin >> q;while (q--) {Solve();}return 0;
}

Honeycomb

我们可以将每一个格子进行染色,至于如何染色我们可以找到如下这个字符
image
然后打表即可,假设我们只能自己走空格,那我们就可以用 \(bfs\) 答案就是经过了几个不同颜色的空格

#include <bits/stdc++.h>using namespace std;const int N = 6e3 + 5;struct node {int x, y, dis;
};int t, n, m, len[N], cnt, qx, qy, zx, zy;int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};bool vis[N][N];char a[N][N];int b[N][N];string s;void bfs() {deque<node> q;q.push_front({qx, qy, 1});while (!q.empty()) {node cur = q.front();q.pop_front();vis[cur.x][cur.y] = true;if (cur.x == zx && cur.y == zy) {cout << cur.dis << "\n";return ;}for (int i = 0; i < 4; i++) {int nx = cur.x + dx[i], ny = cur.y + dy[i];if (nx >= 1 && nx <= 3 + 4 * n && ny >= 1 && ny <= len[nx] && (a[nx][ny] == ' ' || a[nx][ny] == 'T') && !vis[nx][ny]) {if (b[nx][ny] != b[cur.x][cur.y]) {q.push_back({nx, ny, cur.dis + 1});}else q.push_front({nx, ny, cur.dis});}}}cout << "-1\n";
}void Solve() {cin >> n >> m;getline(cin, s);for (int i = 1; i <= 3 + n * 4; i++) {getline(cin, s);len[i] = s.size();for (int j = 0; j < s.size(); j++) {a[i][j + 1] = s[j];if (a[i][j + 1] == 'S') {qx = i, qy = j + 1;}else if (a[i][j + 1] == 'T') {zx = i, zy = j + 1;}}}cnt = 0;for (int i = 1; i <= n * 4; i++) {int tot = (i % 4) / 2;for (int j = 1; j <= len[i]; j++) {if (a[i][j] != '+') {continue;}tot++;if (!(tot % 2) || j == len[i]) {continue;}cnt++;b[i][j + 1] = b[i][j + 2] = b[i][j + 3] = cnt;b[i + 1][j - 1] = b[i + 1][j] = b[i + 1][j + 1] = b[i + 1][j + 2] = b[i + 1][j + 3] = b[i + 1][j + 4] = b[i + 1][j + 5] = cnt;b[i + 2][j - 2] = b[i + 2][j - 1] = b[i + 2][j] = b[i + 2][j + 1] = b[i + 2][j + 2] = b[i + 2][j + 3] = b[i + 2][j + 4] = b[i + 2][j + 5] = b[i + 2][j + 6] = cnt;b[i + 3][j - 1] = b[i + 3][j] = b[i + 3][j + 1] = b[i + 3][j + 2] = b[i + 3][j + 3] = b[i + 3][j + 4] = b[i + 3][j + 5] = cnt;b[i + 4][j + 1] = b[i + 4][j + 2] = b[i + 4][j + 3] = cnt;}}bfs();for (int i = 1; i <= 3 + 4 * n; i++) {for (int j = 1; j <= len[i]; j++) {vis[i][j] = false;b[i][j] = 0;a[i][j] = ' ';}}
}int main() {ios::sync_with_stdio(0);cin.tie(0);for (int i = 1; i < N; i++) {for (int j = 1; j < N; j++) {a[i][j] = ' ';}}cin >> t;while (t--) {Solve();}return 0;
}
/*+---+/12345\
+1234567+\12345/+---++---+       +---+/     \     /     \
+       +---+       +---+\           \     /     \+   +   S   +---+   T   +/     \     /           /
+       +---+       +   +\           \     /     \+---+       +---+       +/                       /
+       +---+       +   +\                 /     \+---+       +---+       +\     /     \     /+---+       +---+*/

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/802122.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

学习vue——自定义指令

一、局部自定义指令二、全局注册自定义指令 三、总结

如何让带参数变量的mysql查询走索引?

1,问题的提出 mysql 5.7的数据库,jx_performance表含索引idx_performance。该索引关联两个字段:`date`, `user_id`。 在运行sql语句时发现,如果where条件采用参数变量,则查询不走索引。图1,带参数变量查询图2,采用字符串常数查询上图1和图2,实际上查询条件一样,因为查…

大发明家

(彩蛋:大样例是从数据里扒的,且没有绑点)。 由于组题人电脑坏了,所以只能写简略题解了(其实是组题人的口胡碎碎念),写的不清晰的和部分分可以听讲题(可能有一些地方我下意识省略了,可以来问我). 首先,生成到完美的时间线的概率是固定的,如果我们假设概率为 \[p = \frac{|完…

acme+cloudflare生成免费证书(自动续期)

acme DNSapi acme DNSapi的作用是在申请证书时使用dns交易,acme可以通过dnsapi在对应的dns管理平台提交对应的dns记录。玩过证书的朋友都知道,证书申请时有三种验证方式邮箱验证:需要邮箱与域名绑定(细节要求我没试过) 文件验证:文件验证时证书管理方会要求你在服务器的指…

pip install volcengine-python-sdk[ark]

解决方案: 需要修改注册表的变量 https://github.com/volcengine/volcengine-python-sdk/issues/5

2024年9月23日 人工智能作业

主题为校园科技节之航天主题,运用了亿图图示中天文学的符号素材进行构图,添加了星球,飞船,宇航员,天文望远镜等航天常见元素构成了太空的场景,并添加了“校园科技节”的文本点明主题,以最简约的形式表达了海报的含义

python面试题

python是什么?Python是一种开放原始码、直译式、可携式、面向对象的程序语言,具有模块、多线程、异常处理以及自动内存管理功能。广泛应用包括Web开发(如Django和Flask框架)、数据科学(如Pandas和NumPy库)、机器学习(如TensorFlow和PyTorch框架)、自动化脚本、科学计算…

基于gin的web开发脚手架模版

一、web开发模式 1.传统的MVC模式:这个模式不太适合大型的web应用。 2.CLD模式链接:https://github.com/Ruan0423/gin-web-Framework 二、目录结构 --web_app-controller-logic-dao-mysql-redis-models-pkg-settingssettings.go-routersrouter.gomain.gogo.modgo.sumconfig.y…

OpenAI o1模型揭秘:通过LLMs学习推理能力

OpenAI推出了o1,这是一种通过强化学习训练的大型语言模型,专门用于进行复杂的推理任务。o1在回答问题之前会“思考”,能够在响应用户之前生成一条长的内部思维链。 在编程竞赛问题(Codeforces)中,OpenAI o1的排名在89%分位,位列美国数学奥林匹克预选赛(AIME)前500名学…

网站数据库为什么连接失败

网站数据库连接失败可能有以下几个常见原因:数据库配置错误:数据库连接参数配置错误,如用户名、密码、主机地址、端口号、数据库名称等配置不正确。 应用程序中的数据库配置文件(如WordPress中的wp-config.php)可能包含了错误的信息。网络问题:数据库服务器与应用程序服务…

Spark(五)运行环境(一)

Local模式不需要其他任何节点资源就可以在本地执行Spark代码的环境,一般用于教学,调试,演示等 在IDEA中运行代码的环境称之为开发环境1、解压缩文件将spark-3.0.0-bin-hadoop3.2.tgz文件上传到Linux并解压缩,放置在指定位置,路径中不要包含中文或空格 压缩文件放在/opt/so…

树上数据结构问题

天天爱跑步 假设现在又一棵树如果一个人要从 \(3\) 跑到 \(5\),那么如果在 \(2\) 点的观察员要满足 \(w[2] = dep[2] - dep[3]\),如果在点 \(4\) 的观察员要满足 \(w[4] = dep[fa[lca]] - dep[3] + dep[lca] - dep[4]\),简单来说就是如果处于 \(i\) 点的观察员可以观察到,那么要…