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 ...
随机推荐
- 分享知识-快乐自己:Struts2 拦截器 与 过滤器
拦截器的使用以及配置: package com.gdbd.interceptor; import com.gdbd.pojo.UserInfo; import com.opensymphony.xwo ...
- 更新github上代码
前面一篇已经实现首次上传代码到github了,本篇继续讲如何把本地更新的代码同步更新到github上 一.clone代码 1.把大神的代码clone到本地,或者clone自己github上的代码,使用 ...
- stl_heap.h
stl_heap.h // Filename: stl_heap.h // Comment By: 凝霜 // E-mail: mdl2009@vip.qq.com // Blog: http://b ...
- Android开发中高效的数据结构
android开发中,在java2ee或者android中常用的数据结构有Map,List,Set,但android作为移动平台,有些api(很多都是效率问题)显然不够理想,本着造更好轮子的精神,an ...
- Android中高效的显示图片之三——缓存图片
加载一张图片到UI相对比较简单,如果一次要加载一组图片,就会变得麻烦很多.像ListView,GridView,ViewPager等控件,需要显示的图片和将要显示的图片数量可能会很大. 为了减少内存使 ...
- 判断CPU是大端还是小端
#include "stdafx.h" #include <iostream> using namespace std; /* #大端模式(Big_endian):字数 ...
- 线段树Final版本
结构体是个好东西... 看着逼格很高 #include<iostream> #include<cstdio> #include<cstdlib> #include& ...
- 1103 Integer Factorization (30)(30 分)
The K-P factorization of a positive integer N is to write N as the sum of the P-th power of K positi ...
- bzoj 4501: 旅行 01分数规划+概率期望dp
题目大意: http://www.lydsy.com/JudgeOnline/problem.php?id=4501 题解: 首先我们不考虑可以删除边的情况下,如何计算期望边数. 然后我们发现这是个有 ...
- 【C&C++】查看代码运行时间
查看代码运行时间有助于更好地优化项目代码 1. Windows平台 windows平台下有两种方式,精度有所不同,都需要包含<windows.h>头文件 1) DWORD GetTickC ...