【Educational Codeforces Round 53 (Rated for Div. 2) C】Vasya and Robot
【链接】 我是链接,点我呀:)
【题意】
【题解】
如果|x|+|y|>n
显然。从(0,0)根本就没法到(x,y)
但|x|+|y|
【代码】
#include <bits/stdc++.h>
#define ll long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
using namespace std;
const int N = 2e5;
int n;
ll x,y;
ll px[N+10],py[N+10];
char s[N+10];
bool ok(int len){
rep1(i,1,n){
if (i+len-1>n) return 0;
ll x0 = px[i-1]-px[0],y0=py[i-1]-py[0];
x0+=px[n]-px[i+len-1];y0+=py[n]-py[i+len-1];
ll temp = abs(x-x0)+abs(y-y0);
if (temp<=len) return 1;
}
return 0;
}
int main(){
#ifdef ccy
freopen("rush.txt","r",stdin);
#endif
scanf("%d",&n);
scanf("%s",s+1);
scanf("%lld%lld",&x,&y);
ll temp = abs(x)+abs(y);
if (temp>n || ( (temp&1) != (n&1) ) ){
puts("-1");
return 0;
}
rep1(i,1,n){
px[i] = px[i-1];py[i] = py[i-1];
if (s[i]=='L') px[i]--;
if (s[i]=='R') px[i]++;
if (s[i]=='U') py[i]++;
if (s[i]=='D') py[i]--;
}
int l = 0,r = n,temp1 = -1;
while (l <= r){
int mid = (l+r)>>1;
if (ok(mid)){
temp1 = mid;
r = mid-1;
}else{
l = mid+1;
}
}
printf("%d\n",temp1);
return 0;
}
【Educational Codeforces Round 53 (Rated for Div. 2) C】Vasya and Robot的更多相关文章
- 【Educational Codeforces Round 48 (Rated for Div. 2) C】 Vasya And The Mushrooms
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 显然在没有一直往右走然后走到头再往上走一格再往左走到头之前. 肯定是一直在蛇形走位.. 这个蛇形走位的答案贡献可以预处理出来.很容易 ...
- 【Educational Codeforces Round 48 (Rated for Div. 2) D】Vasya And The Matrix
[链接] 我是链接,点我呀:) [题意] 告诉你每一行.每一列的异或和. 让你求出一个符合要求的原矩阵. [题解] 显然应该有 a1^a2^....^an = b1^b2^....^bn 也即两边同时 ...
- 【Educational Codeforces Round 53 (Rated for Div. 2)】
A:https://www.cnblogs.com/myx12345/p/9853775.html B:https://www.cnblogs.com/myx12345/p/9853779.html ...
- 【 Educational Codeforces Round 51 (Rated for Div. 2) F】The Shortest Statement
[链接] 我是链接,点我呀:) [题意] [题解] 先处理出来任意一棵树. 然后把不是树上的边处理出来 对于每一条非树边的点(最多21*2个点) 在原图上,做dijkstra 这样就能处理出来这些非树 ...
- 【Educational Codeforces Round 41 (Rated for Div. 2) D】Pair Of Lines
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 如果点的个数<=3 那么直接输出有解. 否则. 假设1,2最后会在一条直线上,则把这条直线上的点都删掉. 看看剩余的点是否在同 ...
- 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) 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)
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个的数的 ...
随机推荐
- centos改动sshport
vi /etc/ssh/sshd_config 找到#Port 22一段,这里是标识默认使用22port.加入一行例如以下: Port 34981 然后保存退出 然后service sshd rest ...
- 深入分析JavaWeb Item47 -- Struts2拦截器与文件上传下载
一.struts2中的拦截器(框架功能核心) 1.过滤器VS拦截器 过滤器VS拦截器功能是一回事. 过滤器是Servlet规范中的技术,能够对请求和响应进行过滤. 拦截器是Struts2框架中的技术. ...
- Getting Installation aborted (Status 7) ApplyParsePerms: lsetfilecon of /syst...【转】
OTA升级失败:原文http://en.miui.com/thread-112197-1-1.html Do you get this "Status 7" error in Re ...
- NOIP2013--火柴排队(树状数组)
转载: 树状数组,具体的说是 离散化+树状数组.这也是学习树状数组的第一题. 算法的大体流程就是: 1.先对输入的数组离散化,使得各个元素比较接近,而不是离散的, 2.接着,运用树状数组的标准操作来累 ...
- Docker For MYSQL 8.0 特别注意修复数据库新的验证方式
从Docker登录MySQL的终端 docker exec -it wordpress-mysql /bin/bash 登录数据库 mysql -u root -p 使用MYSQL数据库 use my ...
- Nginx报错-找不到路径
前言 最近在git bash里输入命令启动Nginx服务,总提示找不到路径,令我困惑不已 我反复检查安装路径和输入命令,确认无误 小技巧:复制路径可直接ctrl+c后在git ba ...
- python 5:str(某一变量)(将其他数字解释为字符串)
age = messege = "Your's age is " + str(age) #将其他数字更改为字符串 print(messege) 运行结果应该是: Your's ag ...
- 我和CSDN的那些事
作者:朱金灿 来源:http://blog.csdn.net/clever101 前些日子收到这样一个邀请: CSDN的工作人员还来电给我确认是否能参加.开始我有点犹豫,毕竟是在工作日的晚上,毕竟离我 ...
- winxp精简版没有IIS的解决办法
首先在“开始”菜单的“运行”中输入“c:\Windows\inf\sysoc.inf”,系统会自动使用记事本打开sysoc.inf这个文件.在sysoc.inf中找到“[Components]”这一段 ...
- 时序分析:KMP算法用于序列识别
考研基础资料之一的<算法与数据结构>,KMP算法作为串匹配的基本算法,为必考题目之一.对于算法入门来说,也是复杂度稍高的一个基本算法. KMP算法作为串匹配的非暴力算法,是为了减少回溯而设 ...