5092: Honey Heist

时间限制: 1 Sec  内存限制: 128 MB

题目描述

0x67 is a scout ant searching for food and discovers a beehive nearby. As it approaches the honeycomb,0x67 can sense an area inside packed with dried honey that can be easily carried back to the nest and stored for winter. However, it must burrow through the honeycomb to reach the cell containing the sweet loot. If 0x67 can create a passage to the honey to help the other ants find it, it will do so before returning to the nest. The cells of the honeycomb are numbered in row major order, so cell IDs can be assigned as shown below:

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.

输入

The input contains two lines. The first line contains five blank separated integers: R N A B X
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.

输出

A single integer K if 0x67 reached the honey at cell B, where B is the Kth cell, otherwise the string No if it was impossible to reach the honey by chewing through N cells or less.

样例输入

6 6 1 45 11
15 16 17 19 26 27 52 53 58 65 74

样例输出

6

来源

mcpc2017


这题的题目意思就是找一个从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的更多相关文章

  1. 武汉科技大学ACM:1005: Soapbear and Honey

    Problem Description Soapbear is the mascot of WHUACM team. Like other bears, Soapbear loves honey ve ...

  2. codeforces 1041A Heist

    electronic a.电子的 heist v.抢劫 in ascending order 升序 indice n.标记 device n.装置设备 staff n.职员 in arbitrary ...

  3. Kattis - honey【DP】

    Kattis - honey[DP] 题意 有一只蜜蜂,在它的蜂房当中,蜂房是正六边形的,然后它要出去,但是它只能走N步,第N步的时候要回到起点,给出N, 求方案总数 思路 用DP 因为N == 14 ...

  4. Codeforces Round #509 (Div. 2) A. Heist 贪心

    There was an electronic store heist last night. All keyboards which were in the store yesterday were ...

  5. Heist

    CF#509 div2 A 第一次用自己的号打CF祭. 题目描述 昨晚有一家电子商店被抢劫了. 昨天在商店里的所有键盘都是从x开始按升序编号的.例如,如果x=4,并且商店中有3个键盘,那么编号就为4, ...

  6. VMware Coding Challenge: The Heist

    类似BackpackII问题 static int maximize_loot(int[] gold, int[] silver) { int[][] res = new int[gold.lengt ...

  7. UVALive 6261 Jewel heist

    题意:珠宝大盗Arsen Lupin偷珠宝.在展厅内,每颗珠宝有个一个坐标为(xi,yi)和颜色ci. Arsen Lupin发明了一种设备,可以抓取平行x轴的一条线段下的所有珠宝而不触发警报, 唯一 ...

  8. 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 在自然生态系统和管理生态系 ...

  9. 五、Pandas玩转数据

    Series的简单运算 import numpy as np import pandas as pd s1=pd.Series([1,2,3],index=['A','B','C']) print(s ...

随机推荐

  1. Web开发者必须知道的10个jQuery代码片段

    在过去的几年中,jQuery一直是使用最为广泛的JavaScript脚本库.今天我们将为各位Web开发者提供10个最实用的jQuery代码片段,有需要的开发者可以保存起来. 1.检测Internet ...

  2. 使用prelu

    一个使用方式:http://blog.csdn.net/xg123321123/article/details/52610919 还有一种是像relu那样写,我就是采用的这种方式,直接把名字从relu ...

  3. CPP-基础:非静态成员函数后面加const,以及mutable修饰成员变量

    非静态成员函数后面加const(加到非成员函数或静态成员后面会产生编译错误),表示成员函数隐含传入的this指针为const指针,决定了在该成员函数中,任意修改它所在的类的成员的操作都是不允许的(因为 ...

  4. Bootsrtap 面包屑导航(Breadcrums)

    Bootstrap面包屑导航是一种基于网站层次信息显示的方式.以博客为例,面包屑导航可以显示发布日期,类别或标签,它们表示当前页面在导航层次结构内的位置. Bootstrap面包屑导航其实是一个简单的 ...

  5. CF895E Eyes Closed (期望)

    题目链接 利用期望的线性性质: \(E(sum) = E(x_l) + E(x_{l+1})+ E(x_{l+2}) +.. E(x_r)\) 然后就考虑对于交换时两个区间元素的改动. 假设这两个区间 ...

  6. 【树链剖分 差分】bzoj3626: [LNOI2014]LCA

    把LCA深度转化的那一步还是挺妙的.之后就是差分加大力数据结构了. Description 给出一个n个节点的有根树(编号为0到n-1,根节点为0).一个点的深度定义为这个节点到根的距离+1.设dep ...

  7. Django2.x中url路由的path()与re_path()参数解释

    在新版本Django2.x中,url的路由表示用path和re_path代替,模块的导入由django1.x版本的from django.conf.urls import url,include变成现 ...

  8. Day07 数据类型(列表,元组,字典,集合)常用操作和内置方法

    数据类型 列表list: 用途:记录多个值(同种属性) 定义方式:[]用逗号分隔开多个任意类型的值 list()造出来的是列表,参数是可迭代对像,也就是可以使用for循环的对像 传入字典,出来的列表元 ...

  9. c++-string-1

    解答注意: 我写的时候考虑了: 1) "     my"(设置flag,为true时表示上一个是非空格字符) 2) "hello John"(最后不是空格结尾, ...

  10. 关于MongoDB分布式高可用集群实现

    一.环境准备 1.本例使用3台Linux主机,IP地址如下: 点击(此处)折叠或打开 Server B Server C 2.根据需要,开启相应主机防火墙的相关端口.本次需要用到3台主机,所以开启这3 ...