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. Summary: rand5构造rand7

    给一个方法,比如 rand5(), 它能够等概率生成 1-5 之间的整数. 所谓等概率就是1,2,3,4,5 生产的概率均为 0.2 .现在利用rand5(), 构造一个能够等概率生成 1- 7 的方 ...

  2. kendo 级联加带搜索的下拉框以及js赋值

    1‘.js给下拉框赋值 $("#UserRole").data("kendoDropDownList").value(dataItem.RoleName); $ ...

  3. 171. Excel Sheet Column Number(简单数学题)

    Given a column title as appear in an Excel sheet, return its corresponding column number. For exampl ...

  4. NetSuite助力各行业企业快速发展

    Oracle NetSuite今天发布了一系列全新技术创新,帮助各行各业企业提升收入.海外扩张以及赋能更多业务用户.最新推出的商务管理.财务管理和分析能力可协助企业利用NetSuite平台来超越客户预 ...

  5. Python入门之面向对象编程(二)python类的详解

    本文通过创建几个类来覆盖python中类的基础知识,主要有如下几个类 Animal :各种属性.方法以及属性的修改 Dog :将方法转化为属性并操作的方法 Cat :私人属性讲解,方法的继承与覆盖 T ...

  6. 深入浅出JVM

    这篇文章简要解析了JVM的内部结构.下面这幅图展示了一个典型的JVM(符合JVM Specification Java SE 7 Edition)所具备的关键内部组件. 上图展示的所有这些组件都将在下 ...

  7. bzoj1634 / P2878 [USACO07JAN]保护花朵Protecting the Flowers

    P2878 [USACO07JAN]保护花朵Protecting the Flowers 难得的信息课......来一题水题吧. 经典贪心题 我们发现,交换两头奶牛的解决顺序,对其他奶牛所产生的贡献并 ...

  8. js 变量提升(JavaScript Scoping and Hoisting)

    原文网址:http://www.cnblogs.com/betarabbit/archive/2012/01/28/2330446.html 这是一篇作者翻译过来的文章,未翻译的原文网址在这里:htt ...

  9. np.tile 和np.newaxis

    output   array([[ 0.24747071, -0.43886742],   [-0.03916734, -0.70580089],   [ 0.00462337, -0.5143158 ...

  10. bzoj 1010 玩具装箱toy -斜率优化

    P教授要去看奥运,但是他舍不下他的玩具,于是他决定把所有的玩具运到北京.他使用自己的压缩器进行压缩,其可以将任意物品变成一堆,再放到一种特殊的一维容器中.P教授有编号为1...N的N件玩具,第i件玩具 ...