目录

  • F. Honeycomb (2018-ACM/ICPC焦作)

F. Honeycomb (2018-ACM/ICPC焦作)

Problem F. Honeycomb
Input file: standard input
Output file: standard output

A honeycomb is a mass wax cells built by honey bees, which can be described as a regular tiling of the
Euclidean plane, in which three hexagons meet at each internal vertex. The internal angle of a hexagon is
120 degrees, so three hexagons at a point make a full 360 degrees. The following figure shows a complete
honeycomb with 3 rows and 4 columns.

Here we guarantee that the first cell in the second column always locates in the bottom right side of
the first cell in the first column, as shown above. A general honeycomb may, on the basis of a complete
honeycomb, lose some walls between adjacent cells, but the honeycomb is still in a closed form. A possible
case looks like the figure below.

Hamilton is a brave bee living in a general honeycomb. Now he wants to move from a starting point to
a specified destination. The image below gives a feasible path in a 3×4 honeycomb from the 1-st cell in
the 2-nd column to the 1-st cell in the 4-th column.

Please help him find the minimum number of cells that a feasible path has to pass through (including
the starting point and the destination) from the specified starting point to the destination.

Input
The input contains several test cases, and the first line contains a positive integer T indicating the number
of test cases which is up to 1e4.
For each test case, the first line contains two integers r and c indicating the number of rows and the
number of columns of the honeycomb, where 2 <= r, c <= 1e3.
The following (4r+3) lines describe the whole given honeycomb, where each line contains at most (6c+3)
characters. Odd lines contain grid vertices represented as plus signs (“+”) and zero or more horizontal
edges, while even lines contain two or more diagonal edges. Specifically, a cell is described as 6 vertices
and at most 6 edges. Its upper boundary or lower boundary is represented as three consecutive minus
signs (“-”). Each one of its diagonal edges, if exists, is a single forward slash (“/”) or a single backslash
(“”) character. All edge characters will be placed exactly between the corresponding vertices. At the
center of the starting cell (resp. the destination), a capital “S” (resp. a capital “T”) as a special character
is used to indicate the special cell. All other characters will be space characters. Note that if any input
line could contain trailing whitespace, that whitespace will be omitted.
We guarantee that all outermost wall exist so that the given honeycomb is closed, and exactly one “S”
and one “T” appear in the given honeycomb. Besides, the sum of r · c in all test cases is up to 2e6.

Output
For each test case, output a line containing the minimum number of cells that Hamilton has to visit moving
from the starting cell (“S”) to the destination (“T”), including the starting cell and the destination. If
no feasible path exists, output -1 instead.

题意是二维平面最短路,不过地图形成蜂窝一样的。我们需要做一个映射。这题题目内存给了一个G,%>_<%,!!!知道这一点后就很好做了。现场题目找不到内存时间,网页提交的地方也没写,下载输入输出的地方才写了。赛后才找到。唉。。。

具体看代码把,映射点

map<pair<int, int>, vector<pair<int, int> > > E;存图,然后bfs。

代码在学校windows都跑不起来,内存用太多了。

注意memset复杂度可能不太对。因为T比较多。

标记点不要用set<pair<int, int> >s了,直接开一个二维数组。内存不要命的开

/**
1
3 412345678901234567890123456789
1  +---+   |   +---+   |
2 /  |  \  |  /  |  \  |
3+---O   +---+   O   +---+      [3, 5]      [3, 17]
4 \  |     |  \     /  |  \
5  +   +   S   +---+   T   +        [5, 11]     [5, 23]
6 /     \     /           /
7+       +---+       +   +      [7, 5]      [7, 17]
8 \           \     /     \
9  +---+       +---+       +        [9, 11]     [9, 23]
0 /                       /
1+       +---+       +   +
2 \                 /     \
3  +---+       +---+       +
4       \     /     \     /
5        +---+       +---+*/
#include <bits/stdc++.h>using namespace std;
const int MAX_R = (1e3 + 10) * 4 + 3;
const int MAX_C = (1e3 + 10) * 6 + 3;char mp[MAX_R][MAX_C];bool point_flag[MAX_R][MAX_C];int t, r, c;int Next[6][2] = {-1, -3, -1, 3, 1, -3, 1, 3, -2, 0, 2, 0};//set<pair<int, int> > point_flag;map<pair<int, int>, vector<pair<int, int> > > E;void init() {for(int i = 3; i <= MAX_R; i += 4) {for(int j = 5; j <= MAX_C; j += 12) {//point_flag.insert(make_pair(i, j));point_flag[i][j] = true;}}for(int i = 5; i <= MAX_R; i += 4) {for(int j = 11; j <= MAX_C; j += 12) {//point_flag.insert(make_pair(i, j));point_flag[i][j] = true;}}
}bool isin(int x, int y) {return x >= 1 && x <= 4 * r + 3 && y >= 1 && y <= 6 * c + 3;
}struct Node {pair<int, int>pos;int step;Node() {}Node(int xx, int yy, int st) {step = st;pos = make_pair(xx, yy);}Node(pair<int, int>p, int st) {step = st;pos = p;}
};int bfs(pair<int, int> &begin_s, pair<int, int> &end_t) {queue<Node>que;set<pair<int, int> >vis;que.push(Node(begin_s, 1));vis.insert(begin_s);while(!que.empty()) {Node now = que.front();que.pop();if(now.pos == end_t) {return now.step;}for(auto it: E[now.pos]) {if(!vis.count(it)) {vis.insert(it);mp[it.first][it.second] = '#';que.push(Node(it, now.step + 1));}}}return -1;
}int main() {init();scanf("%d", &t);while(t--) {E.clear();scanf("%d %d", &r, &c);getchar();for(int i = 1; i <= 4 * r + 3; i++ ) {fgets(mp[i] + 1, MAX_C, stdin);}pair<int, int>begin_s, end_t;for(int i = 1; i <= 4 * r + 3; i++ ) {for(int j = 1; mp[i][j] != '\n'; j++ ) {if(point_flag[i][j]) {if(mp[i][j] == 'S') {begin_s = make_pair(i, j);}if(mp[i][j] == 'T') {end_t = make_pair(i, j);}for(int k = 0; k < 6; k++ ) {int gx = i + Next[k][0];int gy = j + Next[k][1];int mx = i + Next[k][0] * 2;int my = j + Next[k][1] * 2;if(!isin(gx, gy) || !isin(mx, my) || mp[gx][gy] != ' ') {continue;}if(mp[mx][my] == 'S' || mp[mx][my] == 'T' || mp[mx][my] == ' ') {E[make_pair(i, j)].push_back(make_pair(mx, my));}}}}}printf("%d\n", bfs(begin_s, end_t));}return 0;
}

转载于:https://www.cnblogs.com/Q1143316492/p/10092877.html

2018ACM/ICPC亚洲区域赛(焦作)F. Honeycomb相关推荐

  1. 第43届ACM icpc亚洲区域赛焦作站感想

    青岛痛失银牌,焦作又是铜牌一枚,现在想想,前面三个水题,我的原因太大了,老是犯各种zz小错误,明明能秒,却花了大量时间debug,导致三个小时才签完到,最后一个小时,F题的bfs没出来,B题也没出来, ...

  2. 2020年 ICPC 亚洲区域赛(上海)G-Fibonacci

    ICPC 亚洲区域赛(上海) G-Fibonacci 题目 斐波那契数列为1,1,2,3,5,8,13,21,- 可以看到,这个数列有以下特点: 奇,奇,偶,奇,奇,偶- 当 xxx 与 yyy 相乘 ...

  3. 2018年 ACM/ICPC亚洲区域赛 青岛赛区现场赛 比赛总结

    首先祝贺自己收获了ACM生涯中的第二枚铜牌. 首先吐槽一下中石油: 周六早上来到中国石油大学,连个志愿者小姐姐都没看到.(但是看到了女装大佬).报完到之后发现教练少了一张午餐券(要不要这么粗心).为了 ...

  4. 2018亚洲区域赛焦作站参赛总结

    2018年11月26日,我们参加了ACM焦作站的区域赛,第188名,差14名获得铜奖,些许遗憾.下面从赛前准备,比赛过程,赛后反思和规划三方面总结一下. 赛前准备,因为11.3是青岛站的区域赛,所以准 ...

  5. 2021 ICPC 昆明(22-4-17) C L E | 第46届ICPC亚洲区域赛(昆明)

    ICPC 2021 昆明 传送门 补题计划 CLE, C - Cup of Water prob : 在0-V内随机取数灌满1升水的期望操作次数 idea1: 首先将题给的"在0-V内随机取 ...

  6. 第46届ICPC亚洲区域赛(沈阳)L-Perfect Matchings【dp,组合数学】

    正题 题目链接:https://ac.nowcoder.com/acm/contest/24346/L 题目大意 有一张2n2n2n个点的完全图,在上面删除一棵生成树,然后求这张图的完全匹配方案数. ...

  7. 2020 ICPC亚洲区域赛(沈阳)H-The Boomsday Project(双指针+dp)

    H-The Boomsday Project Code1 暴力我为人人区间转移 O{N∑qlog⁡N}O\{N\sum q\log N \}O{N∑qlogN} #include<bits/st ...

  8. 2014ACM/ICPC亚洲区域赛牡丹江现场赛总结

    不知道怎样说起-- 感觉还没那个比赛的感觉呢?如今就结束了. 9号.10号的时候学校还评比国奖.励志奖啥的,由于要来比赛,所以那些事情队友的国奖不能答辩.自己的励志奖班里乱搞要投票,自己又不在,真是无 ...

  9. 2022 ICPC 亚洲区域赛(杭州)赛后总结

    寄!我愿称之为最抽象的一站 20分钟连过两个签到,状态起飞,然后全程坐牢未过一题~~ 不过这次并没有什么遗憾,因为确实够不到铜牌的边缘,看到同校队伍济南站银牌,这一场打铁,我们也就释然了 只能说以后的 ...

最新文章

  1. linux 在终端修改文件,linux命令行学习(42):修改.bashrc文件
  2. Java 集合中的方法性能分析
  3. 需求分析中应该注意的问题
  4. 地震中房子变废墟了,贷款还需要还吗?
  5. SuperSocket 2.0 Preview1 发布,.NET Socket服务器框架
  6. hdu-1088 Write a simple HTML Browser
  7. 更改项目project名称,与项目名称;
  8. Android: app不被系统kill掉
  9. 回溯2--部分全排列
  10. 2016年3月19日 培训复习
  11. 无法创建堆栈的防护页面 解决方法
  12. Android——适配器Adapter与AdapterView
  13. java.util.zip.ZipException: only DEFLATED entries can have EXT descriptor
  14. RK3066开发板的唯一码UUID
  15. matplotlib 配色之内置 colormap
  16. Android项目:基于安卓Android校园零食配送系统app(计算机毕业设计)
  17. opencv-python 使用中遇到的问题
  18. JavaScript函数isFinite()
  19. 如何解决跟这台计算机连接的一个usb设备运行不正常
  20. 惠普HP Prime可编程计算器之工程测量计算

热门文章

  1. php 字符符转整数
  2. MySQL8.0.x 版本安装步骤傻瓜式教程【官方版】
  3. mysqld命令相关介绍
  4. 微信小程序request请求封装;微信小程序封装request请求;uni-app小程序封装request请求;
  5. 原始套接字抓取所有以太网数据包与分析
  6. [html] 写一个水平竖直居中的弹窗,带遮罩层的布局
  7. [vue] 说说你对vue的template编译的理解?
  8. [css] 清除浮动的方式有哪些及优缺点?
  9. [css] 使用flex实现三栏布局,两边固定,中间自适应
  10. [css] 移动端微信页面有哪些兼容性问题及解决方案是什么?