294D - Shaass and Painter Robot

思路:

可以用数学归纳法证明一个结论:整个棋盘黑白相间当且仅当边缘黑白相间。

分奇偶讨论又可得出边缘黑色格个数为n+m-2

这样就可以暴力模拟。

数组开不下保存边缘块有没有被访问,可以用map。

代码:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a)) const int N=1e5+;
const int INF=0x3f3f3f3f;
map<int,int>mp[N];
int main(){
ios::sync_with_stdio(false);
cin.tie();
int x,y,n,m,dx,dy;
string s;
cin>>n>>m>>x>>y;
cin>>s;
if(s[]=='U')dx=-;
else dx=;
if(s[]=='L')dy=-;
else dy=;
int tot=n+m-;
int cnt=;
ll ans=;//原来的一格不要忘记
if(x==||x==n||y==||y==m){
tot--;
mp[x][y]=;
}
while(true){
cnt++;
if(cnt>=5e5)return *puts("-1");
int dis=INF;
if(dx==)dis=min(dis,n-x);
else dis=min(dis,x-);
if(dy==)dis=min(dis,m-y);
else dis=min(dis,y-);
ans+=dis;
x+=dx*dis;
y+=dy*dis;
if(x==)dx=;
else if(x==n)dx=-;
if(y==)dy=;
else if(y==m)dy=-;
if(!mp[x][y]){
tot--;
mp[x][y]=;
}
if(!tot){
cout<<ans<<endl;
return ;
}
}
return ;
}

Codeforces 294D - Shaass and Painter Robot的更多相关文章

  1. Codeforces 752C - Santa Claus and Robot - [简单思维题]

    题目链接:http://codeforces.com/problemset/problem/752/C time limit per test 2 seconds memory limit per t ...

  2. CodeForces - 294A Shaass and Oskols

    //////////////////////////////////////////////////////////////////////////////////////////////////// ...

  3. Codeforces 294B Shaass and Bookshelf:dp

    题目链接:http://codeforces.com/problemset/problem/294/B 题意: 有n本书,每本书的厚度为t[i],宽度为w[i] (1<=t[i]<=2, ...

  4. CodeForces 321 A - Ciel and Robot

    [题目链接]:click here~~ [题目大意]:一个robot 机器人 .能够依据给定的指令行动,给你四种指令,robot初始位置是(0,0).指令一出.robot会反复行动,推断是否能在无限行 ...

  5. Codeforces K. Shaass and Bookshelf(动态规划三元组贪心)

    题目描述: B. Shaass and Bookshetime limit per test    2 secondsmemory limit per test 256 megabytesinput  ...

  6. Codeforces 1073C:Vasya and Robot(二分)

    C. Vasya and Robot time limit per test: 1 secondmemory limit per test: 256 megabytesinput: standard ...

  7. Codeforces 294B Shaass and Bookshelf(记忆化搜索)

    题目 记忆化搜索(深搜+记录状态) 感谢JLGG //记忆话搜索 //一本书2中状态,竖着放或者横着放 //初始先都竖着放,然后从左边往右边扫 #include<stdio.h> #inc ...

  8. Codeforces 294E Shaass the Great

    树形DP.由于n只有5000,可以直接枚举边. 枚举边,将树分成两个子树,然后从每个子树中选出一个点分别为u,v,那么答案就是: 子树1中任意两点距离总和+子树2中任意两点距离总和+子树1中任意一点到 ...

  9. CodeForces 294B Shaass and Bookshelf 【规律 & 模拟】或【Dp】

    这道题目的意思就是排两排书,下面这排只能竖着放,上面这排可以平着放,使得宽度最小 根据题意可以得出一个结论,放上这排书的Width 肯定会遵照从小到大的顺序放上去的 Because the total ...

随机推荐

  1. QLabel 文本内容自动换行显示

    需要把QLabel的WordWrap属性设置成TRUE,可以通过界面设置,也可以通过程序设置  

  2. Apache-Shiro介绍

    Apache Shiro是一个强大且易用的Java安全框架,执行身份验证.授权.密码学和会话管理.使用Shiro的易于理解的API,您可以快速.轻松地获得任何应用程序,从最小的移动应用程序到最大的网络 ...

  3. sql中字符串如何比大小

    从字符串的第一个字符开始比较ASSCII码值,如果相等则看下一个,以此类推. 数字的ASCII码<大写字母的ASCII码<小写字母的ASCII码. ASCII码

  4. sql server2012重复执行创建表视图sql及带行号的视图

    1.可重复操作(创建表,视图)的sql语句判断 IF EXISTS ( SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[re ...

  5. 20154312《网络对抗》Exp2 后门原理与实践

    常见问题快速链接 Handler failed to bind to xxx.xxx.xx.xxx:xxxx 使用Webcam_snap命令提示1411错误,无法正常拍照 常用后门工具实践 Windo ...

  6. 浅谈为什么一个java源文件中只能有一个public类?

    声明,本篇文章为转载 转载 http://blog.csdn.net/bareheadzzq/article/details/6562211 最近在一个java文件中实现了几个类,其中一个声明为pub ...

  7. python 正则表达式匹配ip

    >>> re.match(r'^(([1-9]|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.){3}([1-9]|[1-9]\d|1\d\d|2[0-4]\d| ...

  8. Adobe漏洞攻击

    Adobe漏洞攻击 windows ip 开启msfconsole 进入攻击模块 设置攻击载荷payload 设置相关参数 确定需要修改的参数 exploit生成5303.pdf 将pdf复制到靶机里 ...

  9. Git 基础 —— 安装 配置 别名 对象

    Git 基础学习系列 Git 基础 -- 安装 配置 别名 对象 Git 基础 -- 常用命令 Git 基础 -- 常见使用场景 Git基础 -- Github 的使用 Git 安装 Git下载地址 ...

  10. FJUT 奇怪的数列(线性选择算法)题解

    题意:找出无需数列中位数(偶数为两个中位数平均数向下取整) 思路:用nth_element(a + first,a + k,a+ end + 1)找出中位数,复杂度一般为O(n).这个STL能将 [ ...