1.题目描述 Vasya has got a robot which is situated on an infinite Cartesian plane, initially in the cell (0,0)(0,0). Robot can perform the following four kinds of operations: U — move from (x,y) to (x,y+1) D — move from (x,y)to (x,y−1) L — move from (x,y…
题目:题目链接 思路:对于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 <cs…
CF题目难度普遍偏高啊-- 一个乱搞的做法.因为代价为最大下标减去最小的下标,那么可以看做一个区间的修改.我们枚举选取的区间的右端点,不难发现满足条件的左端点必然是不降的.那么用一个指针移一下就好了 注意特判无解和答案为\(0\)的情况,时间复杂度\(O(n)\)(然而因为人傻常数大所以还跑不过\(O(nlogn)\)的) //minamoto #include<bits/stdc++.h> #define rint register int #define GG return puts(&q…
任意门:http://codeforces.com/contest/1073/problem/C C. Vasya and Robot time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasya has got a robot which is situated on an infinite Cartesian plane, i…
C. Vasya and Robot time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasya has got a robot which is situated on an infinite Cartesian plane, initially in the cell (0,0)(0,0). Robot can perfor…
C. Vasya and Robot time limit per test: 1 secondmemory limit per test: 256 megabytesinput: standard inputoutput: standard output Vasya has got a robot which is situated on an infinite Cartesian plane, initially in the cell (0,0)(0,0)(0,0). Robot can…
[题意]定义f(A,B)为一个字符串,满足: 1.长度为A+B,含有A个‘A',B个'B'. 2.最长的相同字符子串最短. 3.在满足以上2条的情况下,字典序最小. 例如, f(2,3) = BABAB, and f(6,4) = AABAABAABB. Q次询问f(Ai,Bi)的子串[Ci,Di]. Q<=10^3,A,B<=5*10^8,D-C+1<=100,time=2s. [算法]二分+构造 [题解]参考:Editorial 令k为最短的最长相同字符子串,显然k=max(A,B)…
题意:给定长为n的机器人行走路线,每个字符代表上下左右走,可以更改将一些字符改成另外三个字符,定义花费为更改的下标max-min+1, 问从(0,0)走到(X,Y)的最小花费,无解输出-1 n<=2e5,abs(X),abs(Y)<=1e9 思路:第一反应是二分,但其实并没有这个取到等号的严格的性质 不过因为内部可以调整,我们还是可以二分长度,然后看内部调整能不能构造出一组可行解 #include<cstdio> #include<cstring> #include&l…
<题目链接> 题目大意: 一个机器人从(0,0)出发,输入一段指令字符串,和机器人需要在指定步数后到达的终点,问如果机器人需要在指定步数内到达终点,那么需要对原指令字符串做出怎样的改变,假设改变 字符串的最大下标为maxindex,改变字符串的最小下标为minindex,输出最小的 maxindex-minindex+1,即,输出最小的改变字符串的区间长度(该区间内的字符不一定要全部发生改变). 解题分析: 本题可用二分答案求解,先预处理得到x,y的前缀和,即原始指令字符串对x,y的改变所作出…
题目哦 题意:给出一个序列,序列有四个字母组成,U:y+1,D:y-1 , L:x-1 , R:x+1;   这是规则 . 给出(x,y) 问可不可以经过最小的变化这个序列可以由(0,0) 变到(x,y) 注意!!!!是可以变任意序列的!不是只有y变y , x变x ,比赛看错题意导致没A , 分析:这需要借助前置和与后缀和 , 这样的话我就可以知道[L , R] 这个区间需要变化什么 , 没错你可以理解为题目的范围n变为[L , R] , x变为x-xl[L+1]-xr[R+1] ,y同理: 这…