Honey Heist
5092: Honey Heist
时间限制: 1 Sec 内存限制: 128 MB
题目描述

When 0x67 discovers the opening to the honeycomb, it enters the cell. Some ants are stronger than others, depending on their age, so 0x67 can only chew through at most N cells before its jaw wears out and must return to the nest to recuperate. The honeycomb is hexagonal, and each edge length is R cells. 0x67 enters through a hole at location A and must get to the honey at location B by chewing a path through no more than N adjacent cells. Because ants can be competitive, 0x67 wants to reach the honey by chewing through the fewest possible cells. 0x67 can also sense some of the cells are hardened with wax and impossible to penetrate, so it will have to chew around those to reach the cell at location B.
Scout ants have rudimentary computational skills, and before 0x67 begins to chew, it will work out where it needs to go, and compute K, the least number of cells it needs to chew through to get from A to B, where B is the Kth cell. If K > N, 0x67 will not be strong enough to make the tunnel. When 0x67 returns to the nest, it will communicate to its nestmates how many cells it chewed through to get to B, or will report that it could not get to the honey.
输入
R: the length (number of cells) of each edge of the grid, where 2 ≤ R ≤ 20. The total number of cells in the grid can be determined by taking a difference of cubes, R3 − (R − 1)3.


N: the maximum number of cells 0x67 can chew through, where 1 ≤ N < R3 − (R − 1)3.
A: the starting cell ID, This cell is located on one of the grid edges: The cell has fewer than six neighbors.
B: the cell ID of the cell containing the honey, where 1 ≤ B ≤ R3 − (R − 1)3.
X: the number of wax-hardened cells, where 0 ≤ X < (R3 − (R − 1)3) − 1.
The second line contains X integers separated by spaces, where each integer is the ID of a wax-hardened cell.
The ID’s, A, B, and all the ID’s on the second line, are distinct positive integers less than or equal to R3 − (R − 1)3.
输出
样例输入
6 6 1 45 11
15 16 17 19 26 27 52 53 58 65 74
样例输出
6
来源
这题的题目意思就是找一个从A到B的最短路,其中有一些点不能走,问最短路径长度是否大于N
这一题的图和一般的搜索的图不太一样,它是一个六边形的图,但是我们仍然可以用坐标x,y来表示每一个点
其中x为第几行,y为这一行的第几个格子
于是这个题目就变成一个简单的广搜了
要注意的一点是在六边形的上半部分和下半部分x,y转移的状态是不一样的
#include<cstdio>
#include<iostream>
#include<cstring>
#define N 100000 using namespace std;
int r,n,a,b,x;
int x1,y1,x2,y2;
int check[N]= {};
int bound[]; //bound[i]为第i行共有多少个格子 typedef struct
{
int x,y,step;
} ss; int pd(int x,int y) //用来检测x,y点是否合法
{
if(x<||x>*r-||y<||y>bound[x])return ;
return ;
} int f(int x,int y) // 婷姐推的公式,用来计算第x行的第y个数的序号是多少
{
if(x<=r)return r*(x-)+(x-)*(x-)/+y;
return (*r-)*r/+(*r--x)*(x--r)/+y;
} int bfs()
{
if(x1==x2&&y1==y2)return ;
ss team[N];
int c1=,c2=; team[].x=x1;
team[].y=y1;
team[].step=;
check[f(x1,y1)]=; while(c1<c2) //这里就对六边形的上半部分和下半部分做了不同的搜索策略
{
ss now=team[c1];
c1++; // printf("%d %d %d\n",now.x,now.y,f(now.x,now.y)); if(now.x<=r&&pd(now.x-,now.y-)&&check[f(now.x-,now.y-)]==)
{
team[c2].x=now.x-;
team[c2].y=now.y-;
team[c2].step=now.step+;
check[f(team[c2].x,team[c2].y)]=;
if(team[c2].x==x2&&team[c2].y==y2)return team[c2].step;
c2++;
} if(now.x<=r&&pd(now.x-,now.y)&&check[f(now.x-,now.y)]==)
{
team[c2].x=now.x-;
team[c2].y=now.y;
team[c2].step=now.step+;
check[f(team[c2].x,team[c2].y)]=;
if(team[c2].x==x2&&team[c2].y==y2)return team[c2].step;
c2++;
} if(now.x>r&&pd(now.x-,now.y+)&&check[f(now.x-,now.y+)]==)
{
team[c2].x=now.x-;
team[c2].y=now.y+;
team[c2].step=now.step+;
check[f(team[c2].x,team[c2].y)]=;
if(team[c2].x==x2&&team[c2].y==y2)return team[c2].step;
c2++;
} if(now.x>r&&pd(now.x-,now.y)&&check[f(now.x-,now.y)]==)
{
team[c2].x=now.x-;
team[c2].y=now.y;
team[c2].step=now.step+;
check[f(team[c2].x,team[c2].y)]=;
if(team[c2].x==x2&&team[c2].y==y2)return team[c2].step;
c2++;
} if(pd(now.x,now.y-)&&check[f(now.x,now.y-)]==)
{
team[c2].x=now.x;
team[c2].y=now.y-;
team[c2].step=now.step+;
check[f(team[c2].x,team[c2].y)]=;
if(team[c2].x==x2&&team[c2].y==y2)return team[c2].step;
c2++;
} if(pd(now.x,now.y+)&&check[f(now.x,now.y+)]==)
{
team[c2].x=now.x;
team[c2].y=now.y+;
team[c2].step=now.step+;
check[f(team[c2].x,team[c2].y)]=;
if(team[c2].x==x2&&team[c2].y==y2)return team[c2].step;
c2++;
} if(now.x<r&&pd(now.x+,now.y)&&check[f(now.x+,now.y)]==)
{
team[c2].x=now.x+;
team[c2].y=now.y;
team[c2].step=now.step+;
check[f(team[c2].x,team[c2].y)]=;
if(team[c2].x==x2&&team[c2].y==y2)return team[c2].step;
c2++;
} if(now.x<r&&pd(now.x+,now.y+)&&check[f(now.x+,now.y+)]==)
{
team[c2].x=now.x+;
team[c2].y=now.y+;
team[c2].step=now.step+;
check[f(team[c2].x,team[c2].y)]=;
if(team[c2].x==x2&&team[c2].y==y2)return team[c2].step;
c2++;
} if(now.x>=r&&pd(now.x+,now.y)&&check[f(now.x+,now.y)]==)
{
team[c2].x=now.x+;
team[c2].y=now.y;
team[c2].step=now.step+;
check[f(team[c2].x,team[c2].y)]=;
if(team[c2].x==x2&&team[c2].y==y2)return team[c2].step;
c2++;
} if(now.x>=r&&pd(now.x+,now.y-)&&check[f(now.x+,now.y-)]==)
{
team[c2].x=now.x+;
team[c2].y=now.y-;
team[c2].step=now.step+;
check[f(team[c2].x,team[c2].y)]=;
if(team[c2].x==x2&&team[c2].y==y2)return team[c2].step;
c2++;
} } return -; } int main()
{ scanf("%d %d %d %d %d",&r,&n,&a,&b,&x); for(int i=; i<x; i++)
{
int aa;
scanf("%d",&aa);
check[aa]=;
} for(int i=; i<=r; i++)
{
bound[i]=i+r-;
for(int j=; j<=i+r-; j++)
{
if(f(i,j)==a)
{
x1=i;
y1=j;
}
else if(f(i,j)==b)
{
x2=i;
y2=j;
}
}
} for(int i=r+; i<=*r-; i++)
{
bound[i]=r+r-+r+-i;
for(int j=; j<=r+r-+r+-i; j++)
{
if(f(i,j)==a)
{
x1=i;
y1=j;
}
else if(f(i,j)==b)
{
x2=i;
y2=j;
}
}
} int ans=bfs(); if(ans==-||ans>n)printf("No");
else
printf("%d",ans); return ; }
Honey Heist的更多相关文章
- 武汉科技大学ACM:1005: Soapbear and Honey
Problem Description Soapbear is the mascot of WHUACM team. Like other bears, Soapbear loves honey ve ...
- codeforces 1041A Heist
electronic a.电子的 heist v.抢劫 in ascending order 升序 indice n.标记 device n.装置设备 staff n.职员 in arbitrary ...
- Kattis - honey【DP】
Kattis - honey[DP] 题意 有一只蜜蜂,在它的蜂房当中,蜂房是正六边形的,然后它要出去,但是它只能走N步,第N步的时候要回到起点,给出N, 求方案总数 思路 用DP 因为N == 14 ...
- Codeforces Round #509 (Div. 2) A. Heist 贪心
There was an electronic store heist last night. All keyboards which were in the store yesterday were ...
- Heist
CF#509 div2 A 第一次用自己的号打CF祭. 题目描述 昨晚有一家电子商店被抢劫了. 昨天在商店里的所有键盘都是从x开始按升序编号的.例如,如果x=4,并且商店中有3个键盘,那么编号就为4, ...
- VMware Coding Challenge: The Heist
类似BackpackII问题 static int maximize_loot(int[] gold, int[] silver) { int[][] res = new int[gold.lengt ...
- UVALive 6261 Jewel heist
题意:珠宝大盗Arsen Lupin偷珠宝.在展厅内,每颗珠宝有个一个坐标为(xi,yi)和颜色ci. Arsen Lupin发明了一种设备,可以抓取平行x轴的一条线段下的所有珠宝而不触发警报, 唯一 ...
- Genome Sequencing of MuseumSpecimens Reveals Rapid Changes in the Genetic Composition of Honey Bees in California
文章地址:https://academic.oup.com/gbe/article/10/2/458/4810442#supplementary-data Abstract 在自然生态系统和管理生态系 ...
- 五、Pandas玩转数据
Series的简单运算 import numpy as np import pandas as pd s1=pd.Series([1,2,3],index=['A','B','C']) print(s ...
随机推荐
- webpack之postcss集成
项目 为了 兼容各个浏览器,需要加各种 c3前缀,如果手动的加肯定 相对比较麻烦,但是现在有webpack,gulp之类的 工具可以自动给我们加上,可以说效率上加速不少.如果 配置中 做个happyp ...
- Open Cascade:AIS_InteractiveContext如何调用函数选择AIS对象
AIS_InteractiveContext如何调用函数选择AIS对象 myAISContext->MoveTo(point.x, point.y, myView); myAISContext- ...
- Bootstrap 响应式表格
响应式表格 通过把任意的 .table 包在 .table-responsive class 内,您可以让表格水平滚动以适应小型设备(小于 768px).当在大于 768px 宽的大型设备上查看时,您 ...
- flask模板语言
由于Django的模板引擎和Flask中的Jinja2模板引擎有很多一样的地方,所以我将一样的地方总结到了独立的文章中 https://www.cnblogs.com/kuxingseng95/art ...
- Noip2018 考前准备
目录 基础算法 二分 模拟(未补) 高精(未学习) 搜索(未补) 排序 图论 树的直径 树的重心 最短路算法 Spfa Dijkstra Floyd 最小生成树 kruskal 数论 线性筛 线性筛素 ...
- 优化mysql查询
mysql提供了一个特别的explain语句,用来分析查询语句的性能 : explain select ... 1.在所有用于where,order by,group by的列上添加索引 创建索引 添 ...
- FSHC之MCU接口部分理解
|_____________| |_____| |__ ...
- PERL学习之模式匹配
一.简介 模式指在字符串中寻找的特定序列的字符,由反斜线包含:/def/即模式def.其用法如结合函数split将字符串用某模式分成多个单词:@array = split(/ /, $line); ...
- verilog behavioral modeling--sequential and parallel statements
1.Sequential statement groups the begin-end keywords: .group several statements togethor .cause the ...
- Python语言程序设计之三--列表List常见操作和错误总结
最近在学习列表,在这里卡住了很久,主要是课后习题太多,而且难度也不小.像我看的这本<Python语言程序设计>--梁勇著,列表和多维列表两章课后习题就有93道之多.我的天!但是题目出的非常 ...