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 & ...
随机推荐
- poj 3352 双连通分量
至少加几条边成为双连通分量 #include <iostream> #include <cstdio> #include <cstring> using names ...
- stagefright框架(六)-Audio Playback的流程
到目前为止,我们都只着重在video处理的部分,对于audio却只字未提.这篇文章将会开始audio处理的流程. Stagefright中关于audio的部分是交由AudioPlayer来处理,它是在 ...
- SqlBulkCopy使用介绍以及注意事项
SqlBulkCopy,微软提供的快速插入类,针对大批量数据操作,此类效果明显有所提升,以下是微软官方解释: Microsoft SQL Server 提供一个称为 bcp 的流行的命令提示符实用工具 ...
- PHP中的的一个挺好用的函数 array_chunk
- Android开发_关于点击事件
为了防止用户或者测试MM疯狂的点击某个button: 创建一个工具类 public class Tools { private static long lastClickTime; public st ...
- iOS应用之间的跳转与数据传递
在开发的时候遇到需要从其他APP调用自己的APP的需求,比如从Safari中打开APP,并且传递一些信息的需要 1.首先设置自己的URL types 打开项目中的工程文件,打开info选项,在下面的U ...
- 【IOS学习基础】weak和strong、懒加载、循环引用
一.weak和strong 1.理解 刚开始学UI的时候,对于weak和strong的描述看得最多的就是“由ARC引入,weak相当于OC中的assign,但是weak用于修饰对象,但是他们都不会造成 ...
- Aandroid Error之 新导入工程报Unable to resolve target 'android-18'和R cannot be resolved
有段时间没有写安卓了,今天导入以前的项目,结果看到控制台打印出了这样一句:Unable to resolve target 'android-18', 解决方法: 项目->属性->Andr ...
- E - Number Sequence(第二季水)
Description A single positive integer i is given. Write a program to find the digit located in the p ...
- windows系统部署discuz并和javaweb账号连通同步
一.Discuz安装说明 1.安装wamp集成环境 (1)下载wampserver集成环境 网址:(http://wampserver-64bit.en.softonic.com)或百度搜索下载 (2 ...