Codeforces 294D - Shaass and Painter Robot
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的更多相关文章
- Codeforces 752C - Santa Claus and Robot - [简单思维题]
题目链接:http://codeforces.com/problemset/problem/752/C time limit per test 2 seconds memory limit per t ...
- CodeForces - 294A Shaass and Oskols
//////////////////////////////////////////////////////////////////////////////////////////////////// ...
- Codeforces 294B Shaass and Bookshelf:dp
题目链接:http://codeforces.com/problemset/problem/294/B 题意: 有n本书,每本书的厚度为t[i],宽度为w[i] (1<=t[i]<=2, ...
- CodeForces 321 A - Ciel and Robot
[题目链接]:click here~~ [题目大意]:一个robot 机器人 .能够依据给定的指令行动,给你四种指令,robot初始位置是(0,0).指令一出.robot会反复行动,推断是否能在无限行 ...
- Codeforces K. Shaass and Bookshelf(动态规划三元组贪心)
题目描述: B. Shaass and Bookshetime limit per test 2 secondsmemory limit per test 256 megabytesinput ...
- Codeforces 1073C:Vasya and Robot(二分)
C. Vasya and Robot time limit per test: 1 secondmemory limit per test: 256 megabytesinput: standard ...
- Codeforces 294B Shaass and Bookshelf(记忆化搜索)
题目 记忆化搜索(深搜+记录状态) 感谢JLGG //记忆话搜索 //一本书2中状态,竖着放或者横着放 //初始先都竖着放,然后从左边往右边扫 #include<stdio.h> #inc ...
- Codeforces 294E Shaass the Great
树形DP.由于n只有5000,可以直接枚举边. 枚举边,将树分成两个子树,然后从每个子树中选出一个点分别为u,v,那么答案就是: 子树1中任意两点距离总和+子树2中任意两点距离总和+子树1中任意一点到 ...
- CodeForces 294B Shaass and Bookshelf 【规律 & 模拟】或【Dp】
这道题目的意思就是排两排书,下面这排只能竖着放,上面这排可以平着放,使得宽度最小 根据题意可以得出一个结论,放上这排书的Width 肯定会遵照从小到大的顺序放上去的 Because the total ...
随机推荐
- linux 加减符号
[root@LocalWeb01 ~]# aa=11[root@LocalWeb01 ~]# bb=22[root@LocalWeb01 ~]# cc=$aa+$bb[root@LocalWeb01 ...
- 3:2 OGNL 简介
OGNL : (对象图导航语言) 从一个对象到另一个对象 OGNL来源于Xwork: OGNL的作用: OGNL在数据进出值栈的时候进行类型转换
- python解决matplotlib中文坐标值乱码的问题
加上这句话即可 plt.rcParams['font.sans-serif']=['SimHei'] 效果:
- MyBatis学习笔记(八)——Mybatis3.x与Spring4.x整合
转自孤傲苍狼的博客:http://www.cnblogs.com/xdp-gacl/p/4271627.html 一.搭建开发环境 1.1.使用Maven创建Web项目 执行如下命令: mvn arc ...
- presto 0.166概述
presto是什么 是Facebook开源的,完全基于内存的并⾏计算,分布式SQL交互式查询引擎 是一种Massively parallel processing (MPP)架构,多个节点管道式执⾏ ...
- python管道pipe,两个进程,使用管道的两端分别执行写文件动作,带锁(lock)
#coding=utf-8import multiprocessing as mp def write_file(content,lock): lock.acquire() with op ...
- git常用命令3
一. Git 常用命令速查 git branch 查看本地所有分支git status 查看当前状态git commit 提交git branch -a 查看所有的分支git branch -r 查看 ...
- MySQL数据库----多表查询
一.介绍 首先先准备表 员工表和部门表 #建表 create table department( id int, name varchar(20) ); create table employee1( ...
- Python Web学习笔记之SSL,TLS,HTTPS
一. SSL 1. SSL简介 SSL协议位于TCP/IP协议与各种应用层协议之间,为数据通讯提供安全支持.SSL协议可分为两层: SSL记录协议(SSL Record Protocol):它建立在可 ...
- 《网络对抗》拓展:注入shellcode
实践三 知识要求: shellcode:指溢出后执行的能开启系统shell的代码.但是在缓冲区溢出攻击时,也可以将整个触发缓冲区溢出攻击过程的代码统称为shellcode,因此可以将shellcode ...