UESTC_Sea Base Exploration CDOJ 409
When the scientists explore the sea base, they use a kind of auto mobile robot, which has the mission to collect the swatches of resource of the sea base. The collections of the resource are taken to the research ship and classified, and then the research ship goes back to the mainland -- the research centre where scientists can do further research.
The robots have equipments to collect and store the resource, but the equipments have limited capability. Only a small quantity of each kind of recourse is enough for scientific research. So, once the robot has collected one kind of resource, it needs not to collect more. The capability of the robot is fixed and the same as the number of kinds of resource the scientists have already known. So, the robot will collect a list of resource and come back with fruitful results. The resource is buried beneath the surface of the sea base, and the quantity is always enough for the robot to collect if the map indicates that there are some. If the robot doesn't want to collect the resource underneath its location, it can leave it ignored and pass the square freely.
The robot needs a unit electric power to move from a square to another when its container is vacant and only can it move to a square adjacent to it. It needs Ai units to dig and collect the resource marked i. Each of the resource has its weight, so the robot costs Bi units of power per move after it has collected resource i.
During the sea base walk, the robot carries a battery with a certain units(P) of electric power, and the power of it need to be economized, the scientists ask you to calculate the minimal quantity of power the robot will use to collect all kinds of resource and back to the ship.
Input
The first line of the input is an integer T which indicates the number of test cases.
Each of the cases tells the map of the sea base you will explore, The first line will be the M,N,K,P,M (1≤M≤20) is the width of the area, N (1≤N≤20) is the length of the area, and K (1≤K≤10) is the number of kinds of resource, P is the certain capacity of the battery.
Then follows M lines characters indicating the map, each line contains N characters.
There are four kinds of characters, .
, *
, #
and capital letters.
The symbol .
indicate that free space. The *
indicates where the research ship located, notice that once the robot moves back to this area, it will be fetched back to the main ship automatically. You can assume there is only one *
on one map.The #
indicates that the space is blocked of some reason, the capital letters indicate K kinds of resource, and you can assume that there are always K kinds of capital letters (alphabetically from A).
The next K lines follows two integers each line, Ai and Bi.
Output
For each input set output a number of the minimal quantity of power on one single line. Print a warning Impossible
if the minimal quantity of power needed exceeds the capacity of the battery or it's impossible for the robot to accomplish the mission.
解题报告
二进制压下状态。。注意下细节,到基地就强制传送,其他就没啥了
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue> using namespace std;
const int maxn = + ;
int c,r,k,p; char g[maxn][maxn];
int vis[maxn][maxn][ + ];
int dir[][] = {-,,,,,-,,};
int dig_cost[ + ];
int dig_weight[ + ];
int target,sx,sy,ans; typedef struct status
{
int x,y,cost,have,allcost;
status(const int &x,const int & y,const int &cost,const int &have,const int& allcost)
{
this->x = x,this->y = y,this->cost = cost,this->have = have,this->allcost = allcost;
}
}; queue<status>q; void bfs()
{
int flag = ;
while(!q.empty())
{
status s = q.front();q.pop();
int x = s.x,y = s.y ,cost = s.cost , have = s.have , allcost = s.allcost;
if (x == sx && y == sy && !flag)
{
if (have == target && allcost <= ans)
ans = allcost;
continue;
}
if (x == sx && y == sy && flag)
flag = ;
if (g[x][y] <= 'Z' && g[x][y] >= 'A')
{
int t = g[x][y] - 'A';
if ( !((have >> t)& ) )
{
int newhave = have;
newhave |= (<<t);
int newcost = cost + dig_weight[t];
int newallcost = allcost + dig_cost[t];
if (vis[x][y][newhave] == - || newallcost < vis[x][y][newhave])
if(newallcost <= p)
{
vis[x][y][newhave] = newallcost;
q.push(status(x,y,newcost,newhave,newallcost));
}
}
}
for(int i = ; i < ; ++ i)
{
int newx = x + dir[i][],newy = y + dir[i][] , newcost = cost,newhave = have,newallcost = allcost + newcost;
if (newx >= r || newx < || newy >= c || newy < || g[newx][newy] == '#')
continue;
if (vis[newx][newy][newhave] == - || newallcost < vis[newx][newy][newhave])
if(newallcost <= p)
{
vis[newx][newy][newhave] = newallcost;
q.push(status(newx,newy,newcost,newhave,newallcost));
}
}
}
} int main(int argc , char * argv[] )
{
int Case;
scanf("%d",&Case);
while(Case--)
{
ans = 0x7fffffff;
scanf("%d%d%d%d%*c",&r,&c,&k,&p);
memset(vis,-,sizeof(vis));
for(int i = ; i < r ; ++ i)
gets(g[i]);
while(!q.empty())
q.pop();
for(int i = ; i < r ; ++ i)
for(int j = ; j < c ; ++ j)
if (g[i][j] == '*')
{
q.push(status(i,j,,,));
sx = i,sy = j;
i = r ;
break;
}
for(int i = ; i < k ; ++ i)
scanf("%d%d",&dig_cost[i],&dig_weight[i]);
target = ;
for(int i = ; i < k ; ++ i)
target |= (<<i);
bfs();
if (ans == 0x7fffffff)
printf("Impossible\n");
else
printf("%d\n",ans);
}
return ;
}
UESTC_Sea Base Exploration CDOJ 409的更多相关文章
- An Exploration of ARM TrustZone Technology
墙外通道:https://genode.org/documentation/articles/trustzone ARM TrustZone technology has been around fo ...
- 小白解决CENTOS7错误:Cannot find a valid baseurl for repo: base/7/x86_6
刚入手的MacBook想着学点东西,本汪还是决定玩玩CentOS服务器,安装好了VirtualBox + CentOS. 打开一看,懵逼了!命令行! 行吧,先装个图形界面: $sudo yum gro ...
- 分布式系列文章——从ACID到CAP/BASE
事务 事务的定义: 事务(Transaction)是由一系列对系统中数据进行访问与更新的操作所组成的一个程序执行逻辑单元(Unit),狭义上的事务特指数据库事务. 事务的作用: 当多个应用程序并发访问 ...
- base的应用
------------父类 public class Person { public Person(string name,int age) { this.Na ...
- C# base 64图片编码解码
使用WinForm实现了图片base64编码解码的 效果图: 示例base 64编码字符串: /9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKD ...
- c++ builder 2010 错误 F1004 Internal compiler error at 0x9740d99 with base 0x9
今天遇到一个奇怪的问题,拷贝项目后,在修改,会出现F1004 Internal compiler error at 0x9740d99 with base 0x9 ,不管怎么改,删除改动,都没用,关闭 ...
- MVC中的BASE.ONACTIONEXECUTING(FILTERCONTEXT) 的作用
一句话,就是调用base.OnActionExecuting(filterContext)这个后,才会执行后续的ActionFilter,如果你确定只有一个,或是不想执行后续的话,那么可以不用调用该语 ...
- 安装CentOS7文字界面版后,无法联网,用yum安装软件提示 cannot find a valid baseurl for repo:base/7/x86_64 的解决方法
*无法联网的明显表现会有: 1.yum install出现 Error: cannot find a valid baseurl or repo:base 2.ping host会提示unknown ...
- 在ASP.NET Core中使用Angular2,以及与Angular2的Token base身份认证
注:下载本文提到的完整代码示例请访问:How to authorization Angular 2 app with asp.net core web api 在ASP.NET Core中使用Angu ...
随机推荐
- Ajax_post发送
$('#img_file_del_3').click(function() { var data={name:$('#img_file_del_3').attr('name')}; var url=' ...
- redis知识
http://www.cnblogs.com/moon521/p/5301895.html 菜鸟教程:http://www.runoob.com/redis/redis-tutorial.html
- UGUI 帧动画插件
最近在开发一款功夫猫游戏,本来使用Unity Sprite制作,但是发现Sprite对各种分辨率不支持. 看着游戏很简单就使用UGUI制作,在中途发现有很多帧动画播放,使用了Animation调整使用 ...
- Android系统进程Zygote启动过程的源代码分析
文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/6768304 在Android系统中,所有的应用 ...
- 谷歌推出情境感知API
在 Google I/O 2016 大会上,我们宣布推出新的 Google Awareness API,让您的应用可以利用快照和围栏智能应对用户情境,并且仅需占用极少量的系统资源. 所有开发者均可以通 ...
- [汇编学习笔记][第十三章int指令]
第十三章int指令 13.1 int指令 格式: int n, n 为中断类型码 可以用int指令调用任何一个中断的中断处理程序(简称中断例程). 13.4 BIOS和DOS 所提供的中断例程 BIO ...
- js keycode 列表
keycode 8 = BackSpace BackSpace keycode 9 = Tab Tab keycode 12 = Clear keycode 13 = Enter ...
- html布局
1.div <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8 ...
- iOS-设计模式之Block
Block是代码块, Block定义 返回值 (^ 块名)(参数1,参数2…); 在定义Block的时候可以使用typedef 重命名一下. typedef void(^blockName)(NSSt ...
- 控制点:ControlPoint
位于control:Points面板下,kitControl面板的ControlPallette中也存在控制点. 控制点是什么呢?一个数据值.一个传感器的值.比如,温度值,风速值,压力值,光照值,开关 ...