UVA 1622 Robot
题意:
给出n*m个格子,每个格子里有一个机器人,可以执行东南西北四种指令,但是移动出格就会爆炸。给出四种指令的个数,求最多完成多少次指令。
分析:
首先对输入数据进行处理,使得cw≥ce、cn≥cs且先执行东西方向的来回移动比先执行南北方向来回移动更佳。然后执行东西移动,然后排序,对比每次向西移动还是开始南北移动更好。当仅剩西和北两个方向后,模拟至结束。
代码:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;
int main()
{
LL n,m,t=0;
while(cin>>n>>m,m||n)
{
t++;
LL cn,cs,cw,ce,ans=0;
scanf("%lld%lld%lld%lld",&cn,&cs,&cw,&ce);
if(cn<cs)
swap(cs,cn);
if(cw<ce)
swap(ce,cw);
LL t1=n+(m-1)*n*ce*2+(m-1)+(m-1)*(n-1)*cs*2;
LL t2=m+m*(n-1)*cs*2+(n-1)+(m-1)*(n-1)*ce*2;
if(cw-ce)
{
t1+=(m-1)*n;
t2+=(m-1)*(n-1);
}
if(cn-cs)
{
t1+=(m-1)*(n-1);
t2+=m*(n-1);
}
if(t1<t2)
{
swap(m,n);
swap(cn,cw);
swap(cs,ce);
}
int flag=1;
if(ce)
{
ans+=n+(m-1)*n*ce*2;
cw-=ce;
ce=0;
m--;
flag=0;
}
if(cw)
{
ans+=m*n;
--cw;
if(flag)
--m;
}
cw=min(m,cw);
while(cw||cn)
{
if(cs)
{
LL t1=m*n+(n-1)*m*2*cs;
LL t2=m*n+(m-1)*n+(m-1)*(n-1)*(2*cs-1);
if(cn-cs)
{
t1=m*n+(n-1)*m*(2*cs+1);
t2=m*n+(m-1)*n+(m-1)*(n-1)*2*cs;
}
if(t1>t2||!cw)
{
ans+=m+m*(n-1)*cs*2;
cn-=cs;
cs=0;
--n;
if(cn)
ans+=m*n,--cn;
cn=min(n,cn);
}
else
{
ans+=m*n;
--m;
--cw;
}
}
else if(!cw)
ans+=m*cn*(2*n-cn+1)/2,cn=0;
else if(!cn)
ans+=n*cw*(2*m-cw+1)/2,cw=0;
else
{
ans+=m*n;
if(m>n) --m,--cw;
else --n,--cn;
}
}
printf("Case %d: ",t);
printf("%lld\n",ans);
}
return 0;
}
UVA 1622 Robot的更多相关文章
- [ACM_模拟] UVA 12503 Robot Instructions [指令控制坐标轴上机器人移动 水]
Robot Instructions You have a robot standing on the origin of x axis. The robot will be given som ...
- UVa——1600Patrol Robot(A*或普通BFS)
Patrol Robot Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Descripti ...
- 紫书 习题 8-22 UVa 1622 (构造法)
这道题的构造法真的复杂--要推一堆公式--这道题写了几天了--还是没写出来-- 一开始简单的觉得先左右来回, 然后上下来回, 然后把剩下的执行完了好了, 然后就WA. 然后换了个思路, 觉得是贪心, ...
- UVA 1600 Patrol Robot(机器人穿越障碍最短路线BFS)
UVA 1600 Patrol Robot Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu ...
- Uva 12569 Planning mobile robot on Tree (EASY Version)
基本思路就是Bfs: 本题的一个关键就是如何判段状态重复. 1.如果将状态用一个int型数组表示,即假设为int state[17],state[0]代表机器人的位置,从1到M从小到大表示障碍物的位置 ...
- UVa 1600 Patrol Robot (习题 6-5)
传送门: https://uva.onlinejudge.org/external/16/1600.pdf 多状态广搜 网上题解: 给vis数组再加一维状态,表示当前还剩下的能够穿越的墙的次数,每次碰 ...
- UVa 1600 Patrol Robot(三维广搜)
A robot has to patrol around a rectangular area which is in a form of m x n grid (m rows and ncolumn ...
- UVa 1600 Patrol Robot (BFS最短路 && 略不一样的vis标记)
题意 : 机器人要从一个m * n 网格的左上角(1,1) 走到右下角(m, n).网格中的一些格子是空地(用0表示),其他格子是障碍(用1表示).机器人每次可以往4个方向走一格,但不能连续地穿越k( ...
- UVA 1600 Patrol Robot
带状态的bfs 用一个数(ks)来表示状态-当前连续穿越的障碍数: step表示当前走过的步数: visit数组也加一个状态: #include <iostream> #include & ...
随机推荐
- RequireJs运行原理
在require中,根据AMD(Asynchronous Module Definition)的思想,即异步模块加载机制,其思想就是把代码分为一个一个的模块来分块加载,这样无疑可以提高代码的重用. 在 ...
- Oracle SQL函数之日期函数
sysdate [功能]:返回当前日期. [参数]:没有参数,没有括号 [返回]:日期 SQL> SELECT SYSDATE FROM DUAL; SYSDATE ----------- // ...
- Linux下重要日志文件及查看方式
http://os.51cto.com/art/201108/282184_all.htm 1.Linux下重要日志文件介绍 /var/log/boot.log 该文件记录了系统在引导过程中发生的 ...
- Android使用webService
在android中使用webservice,首先要导入Android webservice支持包 ksoap2-android-assembly-3.3.0-jar-with-dependencies ...
- 【IOS学习基础】文件相关
一.沙盒(SandBox) 1.沙盒机制 1> 每个应用都有属于自己的存储空间,即沙盒. 2> 应用只能访问自己的沙盒,不可访问其他区域. 3> 如果应用需要进行文件操作,则必须将文 ...
- css基础之 font的简写规则 以及 自定义 CSS3 @font-face详细用法
Part 1 font简写 CSS的命名规则是用英文字母 数字 和下划线(一般用小写)来命名.简写css font的好处有三:一是写起来方便(就像键盘快捷键):二是简化代码:三是帮助你熟悉和深刻理解c ...
- C++标准程序库读书笔记-第二章新的语言特性
1.基本类型的显式初始化 如果采用不含参数.明确的constructor(构造函数)调用语法,基本型别会被初始化为零: int i1; //undefined value int i2 = int() ...
- 多行文本垂直居中div高度确定
父元素高度确定的多行文本.图片.块状元素的垂直居中的方法有两种: 方法一:将内容写入table(包括tbody.tr.td)中的td标签里,同时设置 vertical-align:middle. cs ...
- SSH安全登录(远程管理)22端口
Linux管理Linux 先加密再发送数据,更安全 一 联机加密工具 非对称钥匙对加密 安装 默认安装 openssh 启动 ...
- php isset — 检测变量是否设置 foreach循环运用
例子 $a = 336 ; $b = 33 ; function large($x,$y){ if((!isset($x))||(!isset($y))){ // echo "this fu ...