CodeForces 578E Walking!】的更多相关文章

题目链接 \(Description\) 给定一个长为\(n\)的足迹序列(只包含\(L,R\)两种字符),你需要\(LRLRLR...\)这样交替在\(L\)和\(R\)上走(第一步可以选择\(L\)也可以选\(R\)).当你在\(L\)时,下一步可以走到任意一个没走过的\(R\):在\(R\)时,下一步可以走到任意一个没走过的\(L\).求走完这个\(L,R\)序列最少需要往回走几次,并输出方案(往回走是指从位置\(i\)走到位置\(j\),\(j\lt i\)).保证存在一组可行方案. \…
题意 略. 题解 好毒瘤啊,我最多就口胡第一问的样子吧. 第一问很显然(跟凤凰县探险队员一样显然),就是每次贪心选长度最大的满足条件的子序列,选不到就折返回来.所以折返的次数很明显就是选出子序列的个数 \(-1\). 考虑第二问,很明显不能暴力拼接子序列,这样很容易被 hack.具体方法剩下的题解有讲. 注意到找到的子序列可以按照开头和结尾分成 \(4\) 类:LL,LR,RL 和 RR. 首先有一个性质:可以将所有的 LR 拼在一起得到一个更长的 LR,RL 同理. 接下来 LL 和 RR 有…
题目链接:https://codeforces.com/contest/1154/problem/D 题解: 贪心思路,没有太阳的时候,优先用可充电电池走,万不得已才用普通电池走.有太阳的时候,如果可充电电池能够充一格电,就用普通电池跑(让可充电池充电),否则就用可充电电池走. AC代码: #include<bits/stdc++.h> using namespace std; ; int n,a,b; bool s[maxn]; int main() { cin>>n>&g…
链接: https://codeforces.com/contest/1272/problem/B 题意: Recently you have bought a snow walking robot and brought it home. Suppose your home is a cell (0,0) on an infinite grid. You also have the sequence of instructions of this robot. It is written as…
Diagonal Walking v.2 CodeForces - 1036B Mikhail walks on a Cartesian plane. He starts at the point (0,0)(0,0), and in one move he can go to any of eight adjacent points. For example, if Mikhail is currently at the point (0,0)(0,0), he can go to any o…
Kuro is living in a country called Uberland, consisting of nn towns, numbered from 11to nn, and n−1n−1 bidirectional roads connecting these towns. It is possible to reach each town from any other. Each road connects two towns aa and bb. Kuro loves wa…
C. Kuro and Walking Route time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Kuro is living in a country called Uberland, consisting of $$$n$$$ towns, numbered from $$$1$$$ to $$$n$$$, and $$…
题目链接:http://codeforces.com/contest/979/problem/C 大致题意 给出n个点,有n-1个边将他们链接.给出x,y,当某一路径中出现x....y时,此路不通.路径(u,v)和(v,u)是不同的. 思路:一开始大神是给每个点都用BFS找出能到的点的路径,同时记录搜索的状态,但出了点小问题,估计修正了也回超时,现在给出大神思路,因为不能自己到自己所以点对数肯定是n*(n-1)这是全部的可能,那我们只要找出不可能的情况相减,那就是答案的对不对?这是肯定的,现在我…
题目连接:http://codeforces.com/contest/979/problem/C 解题心得: 题意就是给你n个点,在点集中间有n-1条边(无重边),在行走的时候不能从x点走到y点,问你任意两点一共有多少种走法,u到v和v到u为不同的走法. 首先要明白的是n个点n-1条边就是一棵树.而在树中任意两点有且仅有一条路径.这样就简单了,先从x点dfs到y点,将唯一的一条路径标记上就将树x点和y点形成的子树分开了.然后不走标记的点就可以再次dfs的得到x点子树上的点数sumx,以及y点子树…
D. Walking Between Houses time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There are nn houses in a row. They are numbered from 11 to nn in order from left to right. Initially you are in th…