【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个的数的 ...
随机推荐
- DM8168 IPNC Boa移植
1.交叉编译openssL 下载openssL-1.0.0.tar.gz在虚拟机下进行交叉编译,生成libcrypto.a及libssl.a.将这两个文件复制到DVRRDK_03.00.00.00/b ...
- ListView无障碍识别整个listView,不识别item,设置了setContentDescription也没实用
点击ListView的时候.无障碍识别到的是整个listView,不会读点击的那个item. 解决的方法是在getView里手动设置: <span style="font-size:1 ...
- ios添加麦克风访问权限
不然程序崩溃: This app has crashed because it attempted to access privacy-sensitive data without a usage d ...
- 《解读window核心编程》 之 注冊表
1 注冊表的作用及组织形式 Windows系统使用注冊表来存储系统和应用程序配置数据.非常多系统和应用程序重要的配置的信息都存储在注冊表中. 注冊表是一种以树型结构组织的数据库.树的每个节点称 作键( ...
- EF + WCF学习笔记——EF实体类序列化
项目中如果 EF + WCF 结合使用,模式应该是EF负责读取数据库,传递数据对象给WCF,WCF再将这些对象传送给客户端.因为WCF传送的对象需要序列化,而EF默认生成的对象并没有序列化,很可能会出 ...
- mysql数据库字符编码修改
mysql数据库字符编码修改 修改数据库的字符集mysql>use mydb mysql>alter database mydb character set utf8; 创建数据库指定数据 ...
- 将TensorFlow模型变为pb——官方本身提供API,直接调用即可
TensorFlow: How to freeze a model and serve it with a python API 参考:https://blog.metaflow.fr/tensorf ...
- 【NOI 2014】 动物园
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=3670 [算法] KMP [代码] #include<bits/stdc++.h ...
- 电脑升级win10后visio的问题
上周由于电脑意外蓝屏,系统从win7升级到了win10,昨天工作写文档时才发现缺少画图的工具,于是按照了visio2013,在编辑设计图时发现,一旦用visio打开或编辑图后再到word里设计图的内容 ...
- mysql如何查询最新插入的数据
在MySQL中,使用auto_increment类型的id字段作为表的主键,并用它作为其他表的外键,形成“主从表结构”,这是数据库设计中常见的用法.但是在具体生成id的时候,我们的操作顺序一般是:先在 ...