#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. DBGrideh 实现自动排序

    一.点击标题自动排序 1.在optioneh中设置:AutosortMarking:=True2.设置DbGridEh的属性:(不一定总要设置,与使用的数据连接有关)sortlocal:=True;3 ...

  2. Python基础知识之字符串操作方法总结

    Python 中字符串也是一种数据类型,针对此数据总结下常用的方法 1,字符串截取,变量[头下标:尾下标],就可以截取相应的字符串,其中下标是从0开始算起,可以是正数或负数,下标可以为空表示取到头或尾 ...

  3. C++STL(vector,map,set,list,bitset,deque)成员函数整理

    补充: vector 删除指定元素: vec.erase(remove(vec.begin(), vec.end(), val),           vec.end());remove()返回的是删 ...

  4. Oracle中spool命令实现的两种方法比较

    ---恢复内容开始--- 要输出符合要求格式的数据文件只需在select时用字符连接来规范格式.比如有如下表 SQL>; select id,username,password from myu ...

  5. 冷备手工完全恢复(recover database,recover tablespace,recover datafile)

    冷备手工完全恢复 1.   手工完全恢复三种级别: recover database: 所有或大部分datafile丢失,一般是在mount状态完成.recover tablespace:    非关 ...

  6. 洛谷【P1236】算24点

    我对状态空间的理解:https://www.cnblogs.com/AKMer/p/9622590.html 题目传送门:https://www.luogu.org/problemnew/show/P ...

  7. keepalive安装和配置

    1.下载安装包并解压 sudo wget http://www.keepalived.org/software/keepalived-1.2.13.tar.gz tar zxvf keepalived ...

  8. 问题6:如何让字典保持有序(使用collections的OrderedDict方法)

    from collections imort OrderedDict d = OrderedDict() d['aa'] = (1, 30) d['bb'] = (2, 31) d['cc'] = ( ...

  9. 人物-IT-雷军:雷军

    ylbtech-人物-IT-雷军:雷军 雷军 (全国工商联副主席,小米科技创始人.董事长) 雷军,1969年12月16日出生于湖北仙桃,毕业于武汉大学,是中国大陆著名天使投资人.  雷军作为中国互联网 ...

  10. 游戏中的 2D 可见性

    转自:http://www.gameres.com/469173.html 拖动圆点转一圈,看看玩家都能看到些什么: 这个算法也能计算出给定光源所照亮的区域.对每条光线,我们可以构建出被照亮区域的光线 ...