题目:题目链接

思路:对于x方向距离与y方向距离之和大于n的情况是肯定不能到达的,另外,如果n比abs(x) + abs(y)大,那么我们总可以用UD或者LR来抵消多余的大小,所以只要abs(x) + abs(y) <= n && (n - abs(x) + abs(y)) % 2 == 0,就一定可以到达终点,判断完之后二分答案长度就可以了

AC代码:

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <list>
#include <cstdlib>
#include <cmath> #define FRER() freopen("in.txt", "r", stdin)
#define FREO() freopen("out.txt", "w", stdout)
#define INF 0x3f3f3f3f using namespace std; const int maxn = + ; int n, cx[maxn], cy[maxn], x, y;
char str[maxn]; bool judge(int t) {
for(int i = t; i <= n; ++i) {
int lx = cx[n] - cx[i] + cx[i - t];
int ly = cy[n] - cy[i] + cy[i - t];
if (abs(x - lx) + abs(y - ly) <= t)
return true;
}
return false;
} int main()
{
cin >> n >> str >> x >> y;
if(abs(x) + abs(y) > n || (abs(x) + abs(y)) % != n % ) {
cout << - << endl;
}
else {
for(int i = ; i < n; ++i) {
if(str[i] == 'U') cx[i + ] = cx[i], cy[i + ] = cy[i] + ;
else if(str[i] == 'D') cx[i + ] = cx[i], cy[i + ] = cy[i] - ;
else if(str[i] == 'L') cx[i + ] = cx[i] - , cy[i + ] = cy[i];
else if(str[i] == 'R') cx[i + ] = cx[i] + , cy[i + ] = cy[i];
}
int l = , r = n;
while(l < r) {
int m = (l + r) >> ;
if(judge(m))
r = m;
else
l = m + ;
}
cout << r << endl;
}
return ;
}

Educational Codeforces Round 53 (Rated for Div. 2) C Vasya and Robot 二分的更多相关文章

  1. Educational Codeforces Round 53 (Rated for Div. 2) C. Vasya and Robot 【二分 + 尺取】

    任意门:http://codeforces.com/contest/1073/problem/C C. Vasya and Robot time limit per test 1 second mem ...

  2. Educational Codeforces Round 53 (Rated for Div. 2) C. Vasya and Robot

    题意:给出一段操作序列 和目的地 问修改(只可以更改 不可以删除或添加)该序列使得最后到达终点时  所进行的修改代价最小是多少 其中代价的定义是  终点序号-起点序号-1 思路:因为代价是终点序号减去 ...

  3. Educational Codeforces Round 53 (Rated for Div. 2) C. Vasya and Robot(二分或者尺取)

    题目哦 题意:给出一个序列,序列有四个字母组成,U:y+1,D:y-1 , L:x-1 , R:x+1;   这是规则 . 给出(x,y) 问可不可以经过最小的变化这个序列可以由(0,0) 变到(x, ...

  4. Educational Codeforces Round 53 (Rated for Div. 2) (前五题题解)

    这场比赛没有打,后来补了一下,第五题数位dp好不容易才搞出来(我太菜啊). 比赛传送门:http://codeforces.com/contest/1073 A. Diverse Substring ...

  5. Educational Codeforces Round 53 (Rated for Div. 2)

    http://codeforces.com/contest/1073 A. Diverse Substring #include <bits/stdc++.h> using namespa ...

  6. Educational Codeforces Round 53 (Rated for Div. 2) E. Segment Sum (数位dp求和)

    题目链接:https://codeforces.com/contest/1073/problem/E 题目大意:给定一个区间[l,r],需要求出区间[l,r]内符合数位上的不同数字个数不超过k个的数的 ...

  7. [codeforces][Educational Codeforces Round 53 (Rated for Div. 2)D. Berland Fair]

    http://codeforces.com/problemset/problem/1073/D 题目大意:有n个物品(n<2e5)围成一个圈,你有t(t<1e18)元,每次经过物品i,如果 ...

  8. Educational Codeforces Round 53 (Rated for Div. 2) E. Segment Sum

    https://codeforces.com/contest/1073/problem/E 题意 求出l到r之间的符合要求的数之和,结果取模998244353 要求:组成数的数位所用的数字种类不超过k ...

  9. Educational Codeforces Round 53 (Rated for Div. 2)G. Yet Another LCP Problem

    题意:给串s,每次询问k个数a,l个数b,问a和b作为后缀的lcp的综合 题解:和bzoj3879类似,反向sam日神仙...lcp就是fail树上的lca.把点抠出来建虚树,然后在上面dp即可.(感 ...

随机推荐

  1. spring和springmvc是单例还是多例

    这么说其实不规范 spring的bean    默认是单例 springmvc的controller    默认是单例 所以最好不要在controller里定义成员变量 都可通过注解 @scope=p ...

  2. 转:error LNK2005: ...already defined in MSVCRTD.lib

    编译错误: Error1error LNK2005: _CrtSetCheckCount already defined in MSVCRTD.lib(MSVCR110D.dll)\libcmtd.l ...

  3. db2数据库备份

    一.离线备份 db2  list  database  directory -----查看有哪些数据库,确定需要备份哪个数据库 db2  disconnect  current -----断开以数据库 ...

  4. selenium报错信息-- Python 中 'unicodeescape' codec can't decode bytes in position XXX: trun错误解决方案

    本以为是缺少utf-8造成的错误,但是加完这个还是报错,于是在网上百度了一下是因为上传的路劲粗无偶导致的 正确的写法是把路劲中“\”变为“\\”,或者在路劲的开头加上“r”,或者在路劲的开头加上“r” ...

  5. Windows Experience Index

    The Windows Experience is still there--even in build 9860.  However, the GUI was retired with Window ...

  6. 将Java应用部署到SAP云平台neo环境的两种方式

    方法1 - 使用Eclipse Eclipse里新建一个服务器: 服务器类型选择SAP Cloud Platform: 点Finish,成功创建了一个Server: Eclipse里选择要部署的项目, ...

  7. 在CesiumVR基础上实现3D左右立体视觉

    整体思路 在VR模块的基础上调整视差,使其随距离发生变化: 左右分屏时,需要将左右屏的横向进行1/2压缩:这是因为3D-TV在对左右格式影像进行合并时,会进行拉伸: 左屏幕的相机相对于原来的(右屏)相 ...

  8. 在.net平台上运行伪JAVA

    由于在一个项目局方要求使用JAVA平台, 而当前又都是.net平台的应用. 重新用JAVA开发工作量太大. 时间也来不及. 想到在.net中有url rewrite功能, 何不先"骗&quo ...

  9. 在Vue将第三方JS库封装为组件使用

    第三方JS库地址:https://github.com/inorganik/CountUp.js 使用NPM进行安装: npm install --save countup 根据官方回答,CountU ...

  10. iOS项目工程及目录结构

    做过一些iOS的项目,不同项目的沉淀没有积累到一起,目录的管理都在后期随着人员的增加越来越混乱,因此在这里做一些梳理,希望达到两个目的. 一套相对通用的目录结构,作为后续项目的模版. 积累相应的基础库 ...