#include<bits/stdc++.h>
using namespace std;
const int N=1e6+6;
int x[N],y[N];
int sx,sy,n;
char s[N];
bool check(int m)
{
    for(int i=1;i<=n-m+1;i++)
    {
        int tx=x[n]-x[i+m-1]+x[i-1];  //当前原来选项造成的横坐标影响
        int ty=y[n]-y[i+m-1]+y[i-1];  //当前原来选项造成的纵坐标影响
        int ex=sx-tx, ey=sy-ty;        //消除当前影响
        if(m>=(abs(ex)+abs(ey)) && (m-abs(ex)-abs(ey))%2==0) //可以构造
            return 1;
    }
    return 0;
}
int main()
{
    scanf("%d",&n);
    scanf("%s",s+1);
    x[0]=y[0]=0;
    for(int i=1;i<=n;i++){
        x[i]=x[i-1];
        y[i]=y[i-1];  //累积前面步数的结果
        if(s[i]=='L')
            x[i]-=1;    //当前步数造成的影响
        else if(s[i]=='R')
            x[i]+=1;
        else if(s[i]=='D')
            y[i]-=1;
        else
        y[i]+=1;
    }
    scanf("%d %d",&sx,&sy);       //终点
    int l=0,r=n,ans=-1;
    while(l<=r){              //二分答案
        int mid=(l+r)>>1;
        if(check(mid))
            ans=mid,r=mid-1;
        else
            l=mid+1;
    }
    printf("%d\n",ans);
}
//待温习

Educational Codeforces Round 53C(二分,思维|构造)的更多相关文章

  1. Educational Codeforces Round 60 C 思维 + 二分

    https://codeforces.com/contest/1117/problem/C 题意 在一个二维坐标轴上给你一个起点一个终点(x,y<=1e9),然后给你一串字符串代表每一秒的风向, ...

  2. Educational Codeforces Round 61 F 思维 + 区间dp

    https://codeforces.com/contest/1132/problem/F 思维 + 区间dp 题意 给一个长度为n的字符串(<=500),每次选择消去字符,连续相同的字符可以同 ...

  3. Educational Codeforces Round 10 B. z-sort 构造

    B. z-sort 题目连接: http://www.codeforces.com/contest/652/problem/B Description A student of z-school fo ...

  4. [Educational Codeforces Round 81 (Rated for Div. 2)]E. Permutation Separation(线段树,思维,前缀和)

    [Educational Codeforces Round 81 (Rated for Div. 2)]E. Permutation Separation(线段树,思维,前缀和) E. Permuta ...

  5. [Educational Codeforces Round 63 ] D. Beautiful Array (思维+DP)

    Educational Codeforces Round 63 (Rated for Div. 2) D. Beautiful Array time limit per test 2 seconds ...

  6. Educational Codeforces Round 40 C. Matrix Walk( 思维)

    Educational Codeforces Round 40 (Rated for Div. 2) C. Matrix Walk time limit per test 1 second memor ...

  7. Educational Codeforces Round 37 (Rated for Div. 2)C. Swap Adjacent Elements (思维,前缀和)

    Educational Codeforces Round 37 (Rated for Div. 2)C. Swap Adjacent Elements time limit per test 1 se ...

  8. Educational Codeforces Round 37

    Educational Codeforces Round 37 这场有点炸,题目比较水,但只做了3题QAQ.还是实力不够啊! 写下题解算了--(写的比较粗糙,细节或者bug可以私聊2333) A. W ...

  9. Educational Codeforces Round 60 (Rated for Div. 2) 题解

    Educational Codeforces Round 60 (Rated for Div. 2) 题目链接:https://codeforces.com/contest/1117 A. Best ...

随机推荐

  1. string(未完待续)

    1.string字符串的长度     可以用   a.length()  来测,或者是a.size() 来测 不可以用strlen(a)来求其长度, sizeof(a)是固定值16, 求的是strin ...

  2. Linux-NoSQL之Redis(一)

    1.Redis介绍 redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zset(s ...

  3. MFC实现COM组件

    一般而言,ATL实现了对COM组件最好的支持,所以不用MFC实现COM组件.但是MFC实际上也是可以实现COM组件的. 一.MFC DLL优点: MFC com组件可以将MFC的类型作为参数进行传递, ...

  4. leetcode 226. Invert Binary Tree(递归)

    Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 Trivia:This problem was ...

  5. 实现两个窗口通信方法-postMessage

    此方案可解决跨域而且跨Iframe,而且http和https之间的交互 首先来看一下基本的语法 otherWindow.postMessage(message, targetOrigin, [tran ...

  6. Arc073_F Many Moves

    传送门 题目大意 有$n$个格子从左到右依次挨着,一开始有两枚棋子分布在$A,B$某一个或两个格子里,有$m$个操作,第$i$次操作要求你把其中一个棋子移到$X_i$上,移动一个棋子的代价是两个格子之 ...

  7. noip模拟赛Bywzj52501 17.10.18

    T1 rob 环形消灭虫子 先想出了一个n^2暴力 然后我们想到 如果从两个连续的点求解 则会出现仅有的两种结果 (因为这两种情况的交是全集) 当时因为Naive求了50次 #include<i ...

  8. uva1160 易爆物

    #include<iostream>#include<cstdio>#include<algorithm>#include<cstdlib>using ...

  9. jenkins pipline 用法收集

    1.下载多个项目 node { stage('clone'){ dir('test1'){ checkout([$class: 'GitSCM', branches: [[name: '*/maste ...

  10. 问题:C# List;结果:C#中数组、ArrayList和List三者的区别

    C#中数组.ArrayList和List三者的区别 分类: [C#那些事] 2013-03-11 00:03 36533人阅读 评论(23) 收藏 举报 目录(?)[+] 在C#中数组,ArrayLi ...