Educational Codeforces Round 53 (Rated for Div. 2) C Vasya and Robot 二分
题目:题目链接
思路:对于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 二分的更多相关文章
- 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 ...
- 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(二分或者尺取)
题目哦 题意:给出一个序列,序列有四个字母组成,U:y+1,D:y-1 , L:x-1 , R:x+1; 这是规则 . 给出(x,y) 问可不可以经过最小的变化这个序列可以由(0,0) 变到(x, ...
- Educational Codeforces Round 53 (Rated for Div. 2) (前五题题解)
这场比赛没有打,后来补了一下,第五题数位dp好不容易才搞出来(我太菜啊). 比赛传送门:http://codeforces.com/contest/1073 A. Diverse Substring ...
- Educational Codeforces Round 53 (Rated for Div. 2)
http://codeforces.com/contest/1073 A. Diverse Substring #include <bits/stdc++.h> using namespa ...
- Educational Codeforces Round 53 (Rated for Div. 2) E. Segment Sum (数位dp求和)
题目链接:https://codeforces.com/contest/1073/problem/E 题目大意:给定一个区间[l,r],需要求出区间[l,r]内符合数位上的不同数字个数不超过k个的数的 ...
- [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,如果 ...
- Educational Codeforces Round 53 (Rated for Div. 2) E. Segment Sum
https://codeforces.com/contest/1073/problem/E 题意 求出l到r之间的符合要求的数之和,结果取模998244353 要求:组成数的数位所用的数字种类不超过k ...
- 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即可.(感 ...
随机推荐
- 转 sqlplus/RMAN/lsnrctl 等工具连接缓慢
AIX上sqlplus /as sysdba rman target / 或者lsnrctl start时或者通过sqlplus system/oracle@orcl这样通过监听连接等方式来登陆 ...
- Tensorflow版Faster RCNN源码解析(TFFRCNN) (2)推断(测试)过程不使用RPN时代码运行流程
本blog为github上CharlesShang/TFFRCNN版源码解析系列代码笔记第二篇 推断(测试)过程不使用RPN时代码运行流程 作者:Jiang Wu 原文见:https://hom ...
- Mvc异常处理器
using System; using System.Text; using EMS.Domains.Core; using System.Web.Mvc; using Json.Net; using ...
- 利用Vagrant and VirtualBox搭建core os环境
利用Vagrant and VirtualBox搭建core os环境 系统环境 ubuntu 14.04 x64 vagrant 1.7.4 virtualbox 4.3.10 git 1.9.1 ...
- 编译安装php容易出现的问题以及解决办法
http://crybit.com/20-common-php-compilation-errors-and-fix-unix/
- Redis list(列表)
Redis列表是简单的字符串列表,列表是有序的,列表中的元素可以重复. 可以添加一个元素到列表的头部(左边)或者尾部(右边) 一个列表最多可以包含 232 - 1 个元素 (40多亿). 1.lpus ...
- zuul prefix
经过测试,书上应该是写错了,如果要全部的路由加前缀,需要将zuul.stripPrefix=true进行设置 而不是书上所说的false
- Linux 网卡驱动的安装
一.网卡驱动安装的一般思路 1.首先从硬 件安装,检查网卡本身故障 2.检查网卡芯片型号(注意不是硬件品牌) 常见的网卡芯片有Intel RC82545EM/Realtek 8139D/ Broadc ...
- C#中Image类与byte[]之间的转换
//将image转化为二进制 public byte[] GetByteImage(Image img) { byte[] bt = null; if (!img.Equals(null)) { us ...
- [论文理解] MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications
MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications Intro MobileNet 我 ...