题目:题目链接

思路:对于x方向距离与y方向距离之和大于n的情况是肯定不能到达的,另外,如果n比abs(x) + abs(y)大,那么我们总可以用UD或者LR来抵消多余的大小,所以只要abs(x) + abs(y) <= n && (n - abs(x) + abs(y)) % 2 == 0,就一定可以到达终点,判断完之后二分答案长度就可以了

AC代码:

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <list>
#include <cstdlib>
#include <cmath> #define FRER() freopen("in.txt", "r", stdin)
#define FREO() freopen("out.txt", "w", stdout)
#define INF 0x3f3f3f3f using namespace std; const int maxn = + ; int n, cx[maxn], cy[maxn], x, y;
char str[maxn]; bool judge(int t) {
for(int i = t; i <= n; ++i) {
int lx = cx[n] - cx[i] + cx[i - t];
int ly = cy[n] - cy[i] + cy[i - t];
if (abs(x - lx) + abs(y - ly) <= t)
return true;
}
return false;
} int main()
{
cin >> n >> str >> x >> y;
if(abs(x) + abs(y) > n || (abs(x) + abs(y)) % != n % ) {
cout << - << endl;
}
else {
for(int i = ; i < n; ++i) {
if(str[i] == 'U') cx[i + ] = cx[i], cy[i + ] = cy[i] + ;
else if(str[i] == 'D') cx[i + ] = cx[i], cy[i + ] = cy[i] - ;
else if(str[i] == 'L') cx[i + ] = cx[i] - , cy[i + ] = cy[i];
else if(str[i] == 'R') cx[i + ] = cx[i] + , cy[i + ] = cy[i];
}
int l = , r = n;
while(l < r) {
int m = (l + r) >> ;
if(judge(m))
r = m;
else
l = m + ;
}
cout << r << endl;
}
return ;
}

Educational Codeforces Round 53 (Rated for Div. 2) C Vasya and Robot 二分的更多相关文章

  1. Educational Codeforces Round 53 (Rated for Div. 2) C. Vasya and Robot 【二分 + 尺取】

    任意门:http://codeforces.com/contest/1073/problem/C C. Vasya and Robot time limit per test 1 second mem ...

  2. Educational Codeforces Round 53 (Rated for Div. 2) C. Vasya and Robot

    题意:给出一段操作序列 和目的地 问修改(只可以更改 不可以删除或添加)该序列使得最后到达终点时  所进行的修改代价最小是多少 其中代价的定义是  终点序号-起点序号-1 思路:因为代价是终点序号减去 ...

  3. Educational Codeforces Round 53 (Rated for Div. 2) C. Vasya and Robot(二分或者尺取)

    题目哦 题意:给出一个序列,序列有四个字母组成,U:y+1,D:y-1 , L:x-1 , R:x+1;   这是规则 . 给出(x,y) 问可不可以经过最小的变化这个序列可以由(0,0) 变到(x, ...

  4. Educational Codeforces Round 53 (Rated for Div. 2) (前五题题解)

    这场比赛没有打,后来补了一下,第五题数位dp好不容易才搞出来(我太菜啊). 比赛传送门:http://codeforces.com/contest/1073 A. Diverse Substring ...

  5. Educational Codeforces Round 53 (Rated for Div. 2)

    http://codeforces.com/contest/1073 A. Diverse Substring #include <bits/stdc++.h> using namespa ...

  6. Educational Codeforces Round 53 (Rated for Div. 2) E. Segment Sum (数位dp求和)

    题目链接:https://codeforces.com/contest/1073/problem/E 题目大意:给定一个区间[l,r],需要求出区间[l,r]内符合数位上的不同数字个数不超过k个的数的 ...

  7. [codeforces][Educational Codeforces Round 53 (Rated for Div. 2)D. Berland Fair]

    http://codeforces.com/problemset/problem/1073/D 题目大意:有n个物品(n<2e5)围成一个圈,你有t(t<1e18)元,每次经过物品i,如果 ...

  8. Educational Codeforces Round 53 (Rated for Div. 2) E. Segment Sum

    https://codeforces.com/contest/1073/problem/E 题意 求出l到r之间的符合要求的数之和,结果取模998244353 要求:组成数的数位所用的数字种类不超过k ...

  9. Educational Codeforces Round 53 (Rated for Div. 2)G. Yet Another LCP Problem

    题意:给串s,每次询问k个数a,l个数b,问a和b作为后缀的lcp的综合 题解:和bzoj3879类似,反向sam日神仙...lcp就是fail树上的lca.把点抠出来建虚树,然后在上面dp即可.(感 ...

随机推荐

  1. java课后思考题(五)

    1.使用Files. walkFileTree()找出指定文件夹下所有扩展名为.txt和.java的文件. import java.io.IOException;import java.nio.fil ...

  2. 转 event 'utl_file I/O':

    The ASH report shows tables and data files with wait event 'utl_file I/O': CHANGES No changes. CAUSE ...

  3. ADC5513

    一 C5513 u32 ADC5513_GetValue(void){  u32 ADValue,i;  bool data_bit = false;   C5513_SCK=0;  C5513_CS ...

  4. Vijos 1002 过河 dp + 思维

    https://www.vijos.org/p/1002 设dp[i]表示跳到了第i个点,需要的最小的步数. 所以复杂度O(L * T), 不行 注意到T最大是10, 所以dp[i]最多只由10项递推 ...

  5. F. Coprime Subsequences 莫比乌斯反演

    http://codeforces.com/contest/803/problem/F 这题正面做了一发dp dp[j]表示产生gcd = j的时候的方案总数. 然后稳稳地超时. 考虑容斥. 总答案数 ...

  6. 【Linux】Ubuntu配置zshell&oh-my-zsh

    zshell:https://archive.codeplex.com/?p=shell oh-my-zsh: https://github.com/robbyrussell/oh-my-zsh 终极 ...

  7. Vue.js之vue-router路由

    vue学习的一系列,全部来自于表哥---表严肃,是我遇到过的讲课最通透,英文发音最好听的老师,想一起听课就去这里吧 https://biaoyansu.com/i/hzhj1206 1概述 vue-r ...

  8. javaweb-servlet生成简单的验证码

    package com.serv; import java.awt.Color; import java.awt.Graphics; import java.awt.image.BufferedIma ...

  9. javaSe-反射2

    //创建实体类 package com.java.chap07.sec03; public class Student { private String name; private Integer a ...

  10. HDU 1864 最大报销额(01背包,烂题)

    题意:被坑惨,单项不能超过600,其实是一张发票上A类/B类/C类的总和分别不能超过600. 思路:此题的数据很烂.用贪心也能过,用01背包也可以.都测试不出到底那些是错的. #include < ...