【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个的数的 ...
随机推荐
- <转>Openstack Ceilometer监控项扩展
Openstack ceilometer主要用于监控虚拟机.服务(glance.image.network等)和事件.虚拟机的监控项主要包含CPU.磁盘.网络.instance.本文在现有监控项的基础 ...
- CodeForces - 749C Voting
C. Voting time limit per test 1 second memory limit per test 256 megabytes input standard input outp ...
- 2-bitmap
在2.5亿个整数中找出不重复的整数,注,内存不足以容纳这2.5亿个整数. 思路: bitmap用一个bit来代表存在还是不存在,现在我们要判断重不重复,则需要三个状态:不存在,存在一个,存在多个.2b ...
- Cracking the Coding Interview 8.7
Given a infinite number of quarters(25cents), dimens(10cents), nickels(5cents) and pennies(1cent), w ...
- BZOJ 4332 FFT+快速幂
思路: 最裸的方程:f[i][j]=Σf[i-1][j-k]*F[k] 诶呦 这不是卷积嘛 f[i]就可以用f[i-1]卷F 求到 但是这样还是很慢 设p[i] 为Σ f[j](1<=j< ...
- Spring Boot (15) pom.xml设置
继承spring-boot-parent 要成为一个spring boot项目,首先就必须在pom.xml中继承spring-boot-starter-parent,同时制定其版本 <paren ...
- bcg库使用心得两则
作者:朱金灿 来源:http://blog.csdn.net/clever101 最近帮同事解决了两个BCG库的使用问题,特记录下来. 一是在outlook风格停靠栏上创建对话框的做法.代码如下: C ...
- java ---书写自己的名字
public class hello { public static void main(String[] args) { // TODO 自动生成的方法存根 System.out.println(& ...
- 程序员客栈与DaoCloud这两家企业联手后,运维工程师要失业了!
2017年1月11日 ,程序员客栈与DaoCloud正式建立合作伙伴关系,为创业企业和团队提供容器应用解决方案.通过与DaoCloud合作,客栈可以更有效地把控开发环节中的不确定因素,解决项目工期不确 ...
- react-native 横向滚动的商品展示
在app中会有这种页面 像这样商品是横向的,而且要滚动,思路是利用 ScrollView 横向的滚动 思路: (a): 横向滚动的整体作为一个组件 ShopCenter {/*** 横向滚动 *** ...