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. 系统报错undefine not symbol armv7

    libz.dylib libsqlite3.dylib libstdc++.dylib 添加这些动态链接库

  2. 单源最短路SPFA

    #include<iostream> #include<queue> #include<cstring> #define INF 0x3f3f3f3f using ...

  3. python暴力破解wifi密码程序

    import time # 破解wifi库 import pywifi from pywifi import const class PoJie(object): def __init__(self, ...

  4. 在行列都排好序的矩阵中找数 【题目】 给定一个有N*M的整型矩阵matrix和一个整数K, matrix的每一行和每一 列都是排好序的。实现一个函数,判断K 是否在matrix中。 例如: 0 1 2 5 2 3 4 7 4 4 4 8 5 7 7 9 如果K为7,返回true;如果K为6,返 回false。 【要求】 时间复杂度为O(N+M),额外空间复杂度为O(1)。

    从对角考虑 package my_basic.class_3; /** * 从对角开始 */ public class Code_09_FindNumInSortedMatrix { public s ...

  5. 自己开发一个APP需要多少钱

    广州APP开发公司[启汇网络]经常遇到有开发定制APP软件需求的企业,通常第一句问的就是“开发一款APP需要多少钱”,在做完客户行业的市场调查后,再了解客... 广州APP开发公司[启汇网络]经常遇到 ...

  6. json数据格式 与 for in

    格式一: var json1={ name:'json', age:'23' }; json1.name='金毛'; 格式二: (比较安全)  属性名字里有空格或者有连字符‘-’或者有保留字例如‘fo ...

  7. laravel中migrate的使用

    migration的使用是大大提高了我们开发的效率,数据库迁移大大的方便了我们.今天我就来给大家分享下migration 首先: laravel提供了我们一些基本的建表的规范: 表名:通常用名词+s的 ...

  8. linux下如何编译运行c程序

    GCC是Linux操作系统下一个非常重要的源代码编译工具,有着许多重要的选项,支持许多不同语言的编译,如C.C++.Ada.Fortran.Objective.Perl.Python.Ruby以及Ja ...

  9. 关于set和multiset的一些用法

    set的一些用法 set的特性 set的特性是,所有元素都会根据元素的键值自动排序,set不允许两个元素有相同的键值. set的一些常用操作函数 insert() insert(key_value); ...

  10. js-dom-EventUtil

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...