#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. php数据结构课程---4、栈(是什么)

    php数据结构课程---4.栈(是什么) 一.总结 一句话总结: 栈(stack),它是一种运算受限的线性表.其限制是仅允许在表的一端进行插入和删除运算. 1.栈的链表实现? 定义node,设置属性d ...

  2. php: xampp安装对应的phalcon版本(3.2.2-php5.6):比如redis-php5.6, php_igbinary-5.6

    php: xampp安装对应的phalcon版本(3.2.2-php5.6):比如redis-php5.6, php_igbinary-5.6 一.php安装redis扩展   1.使用phpinfo ...

  3. SWFObject是什么

    一:简介: SWFObject是一个用于在HTML中方便插入Adobe Flash媒体资源(*.swf文件)的独立.敏捷的JavaScript模块.该模块中的JavaScript脚本能够自动检测PC. ...

  4. 【HDU 6428】Calculate 莫比乌斯反演+线性筛

    题解 代码 #include <bits/stdc++.h> using namespace std; typedef long long ll; const ll mod = 1LL&l ...

  5. java String final + equal == 区别

    java String 是不可改变的类型. String a = "hello2"; String d = "hello"; final String b = ...

  6. redis学习--String数据类型。

    本文摘自:http://www.cnblogs.com/stephen-liu74/archive/2012/03/14/2349815.html 一.概述: 字符串类型是Redis中最为基础的数据存 ...

  7. C++ 播放音频流(PCM裸流)

    直接上代码,如果有需要可以直接建一个win32控制台程序然后将代码拷过去改个文件名就可以用了(注意将声道和频率与你自己的文件对应哦).当然我自己也用VS2008(VS2013好用太多,强烈推荐还是用V ...

  8. Qt Quick之TableView的使用

    本博只是简单的展示TableView的基本使用(TableView.style:TableViewStyle.headerDelegate.rowDelegate.itemDelegate.Table ...

  9. bzoj 2733 永无乡 线段树

    题目: 支持两种操作: 合并两点所在的联通块 查询某点所在联通块内权值第k小. 题解 平衡树启发式合并随便搞一搞就好了. 我写了一个线段树合并 #include <cstdio> #inc ...

  10. Oracle 12C 新特性之在线重命名、迁移活跃的数据文件

    Oracle 数据库 12c 版本中对数据文件的迁移或重命名不再需要太多繁琐的步骤,可以使用 ALTER DATABASE MOVE DATAFILE 这样的 SQL 语句对数据文件进行在线重命名和移 ...