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 ...
随机推荐
- BCB 串口控件的使用 TComm
昨天工作用到了串口通信,MMP的,昨天懵逼了一下午,今天终于整通了,身为菜鸟,大师们是不懂这些心痛的. 进入主题:使用BCB提供的控件TComm编程方便且简单,TComm位于System分类里面. ...
- 使用feof()判断文件结束时会多输出内容的原因
这是原来的代码: #include <stdio.h>int main(){ FILE * fp; int ch; fp = fopen("d:\\aaaaa\ ...
- CTC(Connectionist Temporal Classification)介绍
CTC解决什么问题 CTC,Connectionist Temporal Classification,用来解决输入序列和输出序列难以一一对应的问题. 举例来说,在语音识别中,我们希望音频中的音素和翻 ...
- pandas练习(三)------ 数据分组
探索酒类消费数据 相关数据见(github) 步骤1 - 导入pandas库 import pandas as pd 步骤2 - 数据集 path3 = "./data/drinks.csv ...
- Java面向对象---接口
接口(英文:Interface),在JAVA编程语言中是一个抽象类型,是抽象方法的集合,接口通常以interface来声明.一个类通过继承接口的方式,从而来继承接口的抽象方法. 接口并不是类,编写接口 ...
- python函数里面,一个*是可变参数的元祖,两个*是可变参数的字典
python的函数中,有时会有类似*args,**keys这样的参数,代表的是可变参数,一个*表示元祖,两个*表示字典,就是说这个函数可以接受任何类型的参数,都不会报错,有些函数为了提高可用性,会加这 ...
- python socket编程函数介绍
网上看到一个socket中常用函数的介绍,记录一下 https://blog.csdn.net/rebelqsp/article/details/22109925
- [转载]LinkButton跳转页面及传递参数
在DataList中使用LinkButton按钮(LinkButtonDelete),该按钮用于链接跳转到删除页面.在模板中双击该按钮,跳转到.cs页面.问题是我们如何获得该条信息的ID,如果不知道I ...
- STM32f103C8T6 Bootloader设计(转)
源:STM32f103C8T6 Bootloader设计 STM32F103c8t6通过串口实现IAP在线升级固件
- xml之一
xml基础知识 标记语言<> XML与HTML区别 1.HTML主要用来显示 XML是用来进行数据传输 2.HTML是一种预定义的(<a>表示超链接),xml不是预定义的(& ...