Educational Codeforces Round 53C(二分,思维|构造)
#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(二分,思维|构造)的更多相关文章
- Educational Codeforces Round 60 C 思维 + 二分
https://codeforces.com/contest/1117/problem/C 题意 在一个二维坐标轴上给你一个起点一个终点(x,y<=1e9),然后给你一串字符串代表每一秒的风向, ...
- Educational Codeforces Round 61 F 思维 + 区间dp
https://codeforces.com/contest/1132/problem/F 思维 + 区间dp 题意 给一个长度为n的字符串(<=500),每次选择消去字符,连续相同的字符可以同 ...
- 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 ...
- [Educational Codeforces Round 81 (Rated for Div. 2)]E. Permutation Separation(线段树,思维,前缀和)
[Educational Codeforces Round 81 (Rated for Div. 2)]E. Permutation Separation(线段树,思维,前缀和) E. Permuta ...
- [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 ...
- 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 ...
- 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 ...
- Educational Codeforces Round 37
Educational Codeforces Round 37 这场有点炸,题目比较水,但只做了3题QAQ.还是实力不够啊! 写下题解算了--(写的比较粗糙,细节或者bug可以私聊2333) A. W ...
- Educational Codeforces Round 60 (Rated for Div. 2) 题解
Educational Codeforces Round 60 (Rated for Div. 2) 题目链接:https://codeforces.com/contest/1117 A. Best ...
随机推荐
- Codeforces 876B Divisiblity of Differences:数学【任意两数之差为k的倍数】
题目链接:http://codeforces.com/contest/876/problem/B 题意: 给你n个数a[i],让你找出一个大小为k的集合,使得集合中的数两两之差为m的倍数. 若有多解, ...
- Hibernate错误及解决办法
1.Hibernate 报错:this project is not a myeclipse hibernate project . assuming hibernate 3 cap res:项目名上 ...
- php常用函数htmlspecialchars、strip_tags、addslashes解析
本文章向大家介绍php开发中经常使用到的字符串函数htmlspecialchars.strip_tags.addslashes的使用方法及他们之间的区别,需要的朋友可以参考一下. 1.函数strip_ ...
- 数据交换格式XML和JSON对比
1.简介: XML:extensible markup language,一种类似于HTML的语言,他没有预先定义的标签,使用DTD(document type definition)文档类型定义来组 ...
- FFMPEG 最简滤镜filter使用实例(实现视频缩放,裁剪,水印等)
FFMPEG官网给出了FFMPEG 滤镜使用的实例,它是将视频中的像素点替换成字符,然后从终端输出.我在该实例的基础上稍微的做了修改,使它能够保存滤镜处理过后的文件.在上代码之前先明白几个概念: Fi ...
- Gym - 100851L:Landscape Improved (二分+单调性)
题意: 一个宽度为N的网格图,i上有h[i]高的方块.现在你有W个方块,问怎么放使得最终的最高点最高. 当一个格子的下方,左下方和右下方都有方块那么久可以把方块放到这个格子上.最左端和最右端不能放 ...
- Java Main Differences between HashMap HashTable and ConcurrentHashMap
转自这篇帖子:http://www.importnew.com/7010.html HashMap和Hashtable的比较是Java面试中的常见问题,用来考验程序员是否能够正确使用集合类以及是否可以 ...
- bzoj 4773: 负环 floyd
题目: 对于边带权的有向图,找出一个点数最小的环,使得环上的边权和为负. 2 <= n <= 300. 题解: 我们可以考虑从小到大枚举答案. 然后每次枚举更大的答案的时候就从当前的较小的 ...
- Deferred Shading延迟渲染
Deferred Shading 传统的渲染过程通常为:1)绘制Mesh:2)指定材质:3)处理光照效果:4)输出.传统的过程Mesh越多,光照处理越费时,多光源时就更慢了. 延迟渲染的步骤:1)Pa ...
- docker-建立私有registry
我们知道可以使用hub.docker.com作为我们公共或者私有的registry.但由于服务器在国外的原因,网速会非常的慢.所以我们在利用docker开发构建容器服务时,我们希望能够建立自己的私有r ...