July Challenge 2017 | Chef and Sign Sequences
来源:互联网 发布:风险数据集市 编辑:程序博客网 时间:2024/06/02 07:05
题意
大厨昨天捡到了一个奇怪的字符串 s,这是一个仅包含‘<’、‘=’和‘>’三种比较符号的字符串。记字符串长度为 N,大厨想要在字符串的开头、结尾,和每两个字符之间插入一个正整数,共N + 1 个数。大厨希望插入数字之后,这些比较符号所表达的含义是正确的。举个例子,如果在‘<’前后分别插入 a 和 b,那么应当有 a < b。对于‘=’和‘>’也是类似的。大厨可以在 [1, P] 中任意选择数字插入,同一个数也可以被插入到多个位置。
请你帮大厨计算 P 的最小取值可以是多少。
解题思路
忽略”=”,计算忽略”=”后字符串中连续最长的”<”的长度或者连续最长的”>”的长度。
参考代码
#include <bits/stdc++.h>using namespace std;char s[100000+5];int main(){ int t; cin>>t; while (t--){ cin>>s; int x=0,y=0; int ans1=0; for (int i=0;s[i];i++){ if (s[i]=='>') x++; if (s[i]=='<') x=0; if (x>ans1) ans1=x; } int ans2=0; for (int i=0;s[i];i++){ if (s[i]=='<') y++; if (s[i]=='>') y=0; if (y>ans2) ans2=y; } if (ans1>ans2) cout<<ans1+1<<endl; else cout<<ans2+1<<endl; } return 0;}
阅读全文
0 0
- July Challenge 2017 | Chef and Sign Sequences
- June Challenge 2017 | Chef and the Feast
- July Challenge 2017 | Calculator
- 【Codechef】February Challenge 2015 Chef and Strings
- codechef November Challenge 2014 .Chef and Churu
- [多维FFT Bluestein′s Algorithm] Codechef October Challenge 2017 .Chef and Horcrux
- [点分树] Codechef December Challenge 2017. Chef, Leonardo And Queries
- July Challenge 2017 | Whats in the Name
- codechef July Challenge 2014
- [杂题] Codechef July Challenge 2017 #MULDIG Multiplication Program
- [数学 FFT] Codechef July Challenge 2017 #APRPS Irrational Root
- codechef july月赛 Chef's Dream
- Codechef July Challenge 2014部分题解
- CodeChef Chef and Segments
- Chef and Digits
- codechef Chef and sequence
- codechef Chef and Swaps
- Codechef Chef and Reversing
- lua 函数初识(三)
- 找符合条件的最小子串
- 推荐一个博客,ACM,NOIP,NOI,专题讲解
- 【Web】Vue2.0 音乐APP实战中的知识点总结(一)
- android 设置textview的字数
- July Challenge 2017 | Chef and Sign Sequences
- markdown 图片索引
- HTML特殊字符编码对照表
- 六、JAVA基础语法(4)
- poj 3009 dfs
- HDU 2845 Beans(dp+求两次最达不连续子序列和)
- matlab常用命令大全
- ZOJ 3829 Known Notation(模拟+YY)——The 2014 ACM-ICPC Asia Mudanjiang Regional Cont
- 从入门到入门-Spring Boot-入门