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 ...
随机推荐
- Django添加tinyMCE编辑器
tinymce的使用方法很简单,只需要在html页面中包含如下: <!-- Place inside the <head> of your HTML --> <scrip ...
- 如何计算CDS view里两个时间戳之间的天数间隔
ABAP透明表里的时间戳,数据类型为dec: 有个需求:计算这两个时间戳之间的天数间隔,丢弃时间戳年-月-日8位后面的小时:分钟:秒. 举个例子:如果时间戳是20180918173132,丢弃1731 ...
- debug1: expecting SSH2_MSG_KEX_ECDH_REPLY解决
设置mtu ifconfig en1 mtu 1200 代理工具 退出lantern,退出shadowsocks
- QSting, QChar, char等的转换
1,QChar 转换char: char QChar::toLatin1();char QChar::toAscii(); 2,Char转QChar: QChar(char ch); 3,QStrin ...
- 漫谈 Clustering (4): Spectral Clustering<转载>
转自http://blog.pluskid.org/?p=287 如果说 K-means 和 GMM 这些聚类的方法是古代流行的算法的话,那么这次要讲的 Spectral Clustering 就可以 ...
- Luogu P1782 旅行商的背包
题目传送门 卡常背包果然名不虚传 算法主体就是两种背包分开跑,先跑多重背包,再跑奇货 不知道为什么,这题二进制拆分好像要比单调队列优化快一些 然后这题毒瘤的地方就出来了: 如果一件物品的体积\(\ti ...
- vuejs 中 select 动态填充数据,后台的数据
selected:"A" 对 selected:A 错. 变量不用引号. 内容一定要引号. https://jsfiddle.net/rgnuaw30/ ...
- shell脚本,awk如何处理文件中上下关联的两行。
文件d.txt如下内容 ggg 1portals: 192.168.5.41:3260werew 2portals: 192.168.5.43:3260 如何把文件d.txt内容变为如下内容 ggg ...
- 【dp】数字游戏&寒假祭
区间DP 题目描述 丁丁最近沉迷于一个数字游戏之中.这个游戏看似简单,但丁丁在研究了许多天之后却发觉原来在简单的规则下想要赢得这个游戏并不那么容易.游戏是这样的,在你面前有一圈整数(一共n个),你要按 ...
- 初涉倍增&&LCA【在更】
一种特殊的枚举算法 什么是倍增 顾名思义,即每一次翻倍增加.那么,这样我们就有了一种$O(logn)$阶的方法处理枚举方面的问题了. 参考:[白话系列]倍增算法 一些题目 [倍增]luoguP1613 ...