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. Stream.iterate方法与UnaryOperator

    前提:本人在翻看<Java核心技术II>的时候在p17的时候发现一段代码不是很明白.不知道为什么就输出了1,2,3,4,5,6,7,8,9,10,...也不知道n-n.add(BigInt ...

  2. urllib基础-构造请求对象,设置用户代理User-Agent

    有的网页具有一些反爬机制,如:需要浏览器请求头中的User-Agent.User-Agent类似浏览器的身份证. 程序中不设置User-Agent.默认是Python-urllib/3.5.这样网站就 ...

  3. python_112_断言

    #断言 如果满足断言的执行程序,如果不满足则抛错误 assert type(1) is int print('断言正确的话,就继续执行') # assert type('a') is int #Ass ...

  4. CPP-基础:友元

    友元可以是一个函数,该函数被称为友元函数:友元也可以是一个类,该类被称为友元类. 我们已知道类具有封装和信息隐藏的特性.只有类的成员函数才能访问类的私有成员,程序中的其他函数是无法访问私有成员的.非成 ...

  5. nyoj-586-疯牛|poj-2456-Aggressive cows

    http://acm.nyist.net/JudgeOnline/problem.php?pid=586 http://poj.org/problem?id=2456 解题思路:最大化最小值二分答案即 ...

  6. Bootstrap历练实例:基本按钮群组

    <!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...

  7. OC各种遍历方法的效率比较

    看了一篇博客,挺有意思,OC各种遍历方法的效率,打算自己也测试一番.看看,究竟哪一个的效率更好一些! 准备工作:懒加载一个数组,创建一千万个对象添加到数组. #pragma mark - Lazy M ...

  8. noip_最后一遍_2-图论部分

    大体按照 数学 图论 dp 数据结构 这样的顺序 模板集 这个真的只有模板了……………… ·spfa #include<bits/stdc++.h> using namespace std ...

  9. 【计算机网络】Session机制

    1. Http请求中Session机制 先简单说一下HTTP请求中的Session机制:Session数据保存在服务器端,SessionID保存在客户端的Cookies中(关闭浏览器时过期).当客户端 ...

  10. java之 List、Set、ArraylIst、 LinkList

    LIst与set概述 List Set 1.ArrayList是实现了基于动态数组的数据结构,LinkedList基于链表的数据结构.      2.对于随机访问get和set,ArrayList优于 ...