题目链接:https://vjudge.net/contest/148585#problem/H

Line Gimmick

You are in front of a linear gimmick of a game. It consists of $N$ panels in a row, and each of them displays a right or a left arrow.

You can step in this gimmick from any panel. Once you get on a panel, you are forced to move following the direction of the arrow shown on the panel and the panel will be removed immediately. You keep moving in the same direction until you get on another panel, and if you reach a panel, you turn in (or keep) the direction of the arrow on the panel. The panels you passed are also removed. You repeat this procedure, and when there is no panel in your current direction, you get out of the gimmick.

For example, when the gimmick is the following image and you rst get on the 2nd panel from the left, your moves are as follows.

  • Move right and remove the 2nd panel.
  • Move left and remove the 3rd panel.
  • Move right and remove the 1st panel.
  • Move right and remove the 4th panel.
  • Move left and remove the 5th panel.
  • Get out of the gimmick.

You are given a gimmick with $N$ panels. Compute the maximum number of removed panels after you get out of the gimmick.

Input

The input consists of two lines. The first line contains an integer $N$ ($1 \leq N \leq 100,000$) which represents the number of the panels in the gimmick. The second line contains a character string $S$ of length $N$, which consists of '>' or '<'. The $i$-th character of $S$ corresponds to the direction of the arrow on the $i$-th panel from the left. '<' and '>' denote left and right directions respectively.

Output

Output the maximum number of removed panels after you get out of the gimmick.

Sample Input 1

7
>><><<<

Output for the Sample Input 1

7

Sample Input 2

5
>><<<

Output for the Sample Input 2

5

Sample Input 3

6
><<><<

Output for the Sample Input 3

6

Sample Input 4

7
<<><<>>

Output for the Sample Input 4

5

大概题意:一串由“>”和“<”组成的字符串,“>”表示向右走一步,“<”表示向左走一步,从任意一个位置开始走,每次按照当前位置上的命令走一步,再删去这个字符,问最多能走多少。

分析:非常精妙的一道题目,我们考虑任意处开始走,如下一个命令一致,则继续走,否则掉头,那么其实连续一段相同的命令(如“>>>>>”或“<<<”等)并不影响最终能否走完,问题就简化为一串由“>”和“<”间隔排列的字符串能否被走完,那么根据首尾字符,可以分为三种情况:1、<><>……<><>;2、<><>……<><(反过来的情况也一样);3、><><><><;

第一种情况肯定不可行,因为无法从边界往回走,所以只能最后到达边界,而且又有两个边界,就不可行了。

第二种情况可以把字符串看成一段第一种情况下的串+一个单独的朝里的箭头,从第一段的中间开始走,经过一左一右消,到达有朝里箭头的一端,再掉头走到另一个边界

第三种情况可以看成第二种情况在另一端添上一个朝里的箭头,因为第二种情况成立,且走到最后一个边界时不用掉头,所以可以走到最后,即改情况成立

所以只要正反各走一趟,找到离边界最近的一个朝里箭头即可

贴代码,短的奇诡……

#include<cstdio>
#include<algorithm>
using namespace std;
int n;
int main(){int i,L=0,R;char ch;for (scanf("%d",&n),ch=getchar();ch!='<' && ch!='>';ch=getchar());for (i=1;i<=n;ch=getchar(),++i){if (ch=='<') R=i;if (ch=='>' && L==0) L=i;}printf("%d\n",max(n-L+1,R));return 0;
}

【写的有漏洞的,欢迎路过大神吐槽】

2017/1/22 22:30:07

Ending.

【ACM_1】H - Line Gimmick相关推荐

  1. 【八】 H.266/vvc中对称MVD模式(SMVD)

    一.前言 对称MVD模式(symmetric MVD mode ,SMVD)是VVC提出的一种双向预测时MVD语法单元传输模式.在使用对称MVD模式,传输双向预测信息时不需要传list 0和list ...

  2. 【九】 H.266/VVC中帧间仿射运动补偿预测

    一.前言 HEVC中在进行运动补偿时只考虑了平移运动,而在真实的世界存在各种运动,例如缩放.旋转等非平移运动.在H.266/VVC中提出了基于块的仿射变换运动补偿预测.如下图所示,一个块的仿射运动向量 ...

  3. 【H2645】H.264的宏块和H.265的编码树单元总结

    一.H.264宏块 1.什么是宏块? 先看下面两张图,就能大体知道宏块指的是哪了. 将连续几帧图像分为一组(GOP)在H264中称为一个序列(sequence): 将每帧图像(Frame)划拉几道分成 ...

  4. 【笔记】H.265/HEVC 视频编码(四)——预测编码

    预测编码时视频编码中的核心技术之一.对于视频信号来说,一幅图像内邻近像素之间有较强的空间相关性,相邻图像之间有较强的时间相关性.因此采用帧内预测和帧间预测的方式,去除视频的空域和时域的相关性.视频编码 ...

  5. 【C++】.h文件与.c文件的区别

    C++源文件的编译过程与.c.h文件的区别 编译器的处理过程 要理解.c文件与.h文件有什么不同之处,首先需要弄明白编译器的工作过程.一般说来编译器会做以下几个过程: 预处理阶段: 词法与语法分析阶段 ...

  6. 【数据压缩】H.264文件解析和码流分析

    一.实验课要求 选择一个.mp4或者.264文件. 在码流分析仪软件中打开该文件,从几个层次进行分析: 分析SPS和PPS里都包含哪些主要的信息,给出参数值.(例如分辨率.帧率.GOP结构等等) 以一 ...

  7. 【十三】 H.266/VVC | 帧间预测技术 | 解码端运动向量修正技术(DMVR)

    目的:为了提高merge模式下双向预测MV的准确性 基本思路:双向预测是在list0和list1中分别寻找一个运动向量,然后将MV0和MV1所指向的预测块进行加权得到最终预测块,而DMVR技术不是直接 ...

  8. 【笔记】H.265/HEVC 视频编码(三)——编码结构

    H.265/HEVC在编解码的设计上添加了多种新的语法结构,使得H.265/HEVC在压缩效率和网络适应性两个方面有显著提升. 一.编码结构 1.分层处理架构 视频序列是由若干连续时间连续的图像组成的 ...

  9. 【idea】Command line is too long. Shorten command line for XXXApplication

    Command line is too long. Shorten command line for XXXApplication or also for Spring Boot default- 问 ...

最新文章

  1. strtok()思考
  2. 关闭Delphi的RTTI
  3. [PAT乙级]1020 月饼
  4. span组件内容的刷新(笔记)
  5. python绝对值函数fabs_Python中abs()和math.fabs()区别
  6. 1.4. trac.ini
  7. 串口命令自动发送_WIFI模块开发教程之W600基础篇3:串口通讯
  8. php $smarty-display,display - [ smarty完全中文手册 ] - 在线原生手册 - php中文网
  9. 如何使用JMeter建立webSocket连接
  10. 计算机系统基础lab2(二进制炸弹实验)
  11. 适用于Win7系统下Intel 7代核心显卡驱动程序
  12. Linux系统关闭virbr0
  13. Qt Style Sheet实践(二):组合框QComboBox的定制
  14. 某小说App返回数据 解密分析
  15. excel怎么筛选?教你一个简单粗暴的筛选技巧
  16. 前端初学,记下标签以后参考
  17. 目前使用计算机的内存和外存,简述计算机内存和外存区别及常用外存有哪些
  18. [深度学习 - 实战项目] CRAFTCRNN_seq2seq图片文字提取
  19. Windows 下自定义某类型文件图标(例如.h5,.ipynb)
  20. IBM ServerGuide 8.50

热门文章

  1. DJ9-3 DMA 方式
  2. 用python爬虫制作图片下载器(超有趣!)
  3. 给中年工程师的忠告[转载]
  4. LockSupport的park/unpark分析
  5. 计算机组成原理第一章
  6. No qualifying bean of type [com.*.*.dao.InfoDao] found for :错误!
  7. AToken每日简讯 1.11 星期五
  8. CCF-CSP Python Cheat Sheet
  9. android 图片上动态添加文字,摘抄 android图片中添加文字水印
  10. 拼音输入法,提高码字效率