Codility:Titanium 2016 challenge:BracketsRotation
发现codility上很难找到自己的代码,所以来存一下。
用的一种水法,不知道是结论对还是数据水。
处理出所有极大合法串最后就只剩)))((((状的括号,然后枚举右端点,左端点单调。
但是未匹配点数量为奇数时有点尴尬,我直接把答案减1水过去了,似乎总是能找到一个极大合法串中的括号修改后匹配多出来的这个括号?
#define MN 300001
int st[MN],top,mmh=,w[MN];
inline int max(int a,int b){return a>b?a:b;}
int solution(string &S, int K) {
top=;
int i;
for (i=;S[i];i++){
w[i]=S[i]==')';
if (top&&!w[st[top]]&&w[i]) top--;else st[++top]=i;
}
if (top==) return i;
int L=,a[]={,};st[]=-;st[top+]=i;
for (i=;i<=top;i++){
a[w[st[i]]]++;
while (((a[]+)/+(a[]+)/)>K&&L<i) a[w[st[++L]]]--;
mmh=max(st[i+]-st[L]--((a[]+a[])&),mmh);
}
return mmh;
}
Codility:Titanium 2016 challenge:BracketsRotation的更多相关文章
- [转]NLP Tasks
Natural Language Processing Tasks and Selected References I've been working on several natural langu ...
- 2016.11.14 MIT challenge之课程总览
Degree Chartshttp://catalog.mit.edu/degree-charts/computer-science-engineering-course-6-3/ MIT Chall ...
- 2016.10.08--Intel Code Challenge Final Round--D. Dense Subsequence
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- codechef May Challenge 2016 CHSC: Che and ig Soccer dfs处理
Description All submissions for this problem are available. Read problems statements in Mandarin Chi ...
- codechef May Challenge 2016 FORESTGA: Forest Gathering 二分
Description All submissions for this problem are available. Read problems statements in Mandarin Chi ...
- codechef May Challenge 2016 LADDU: Ladd 模拟
All submissions for this problem are available. Read problems statements in Mandarin Chinese, Russia ...
- 深圳 Maker Faire 2016 & Microsoft Booth
首先,感谢Hackster.io和微软,因为发表在Hackster.io的项目<A fall detection system based on Arduino, Windows and Azu ...
- (转) Summary of NIPS 2016
转自:http://blog.evjang.com/2017/01/nips2016.html Eric Jang Technology, A.I., Careers ...
- python 2016 大会 pyconsk ppt ---python dtrace
https://github.com/pyconsk/2016-slides PyCon SK 2016 - March 2016 1DTrace and PythonJesús Cea Aviónj ...
随机推荐
- 【python】列表
>>> mix = [2,3.4,"abc",'中国',True,['ab',23]]>>> mix[2, 3.4, 'abc', '中国', ...
- My Go Resolutions for 2017(from Russ cox's blog)
我的2017年Go决议 一年之季始于春,我认为写一些今年我希望在Go上做的东西是有意义的. 我每年的目标是帮助Go开发人员.我想确保我们在Go团队中所做的工作对Go开发者有重大的积极影响.可能听起来很 ...
- Python删除list中多个相同元素
pop和remove方法都可以删除list中的元素,个人更倾向于使用remove方法,因为在删除过程中不会打印信息,安静的把任务完成. pop方法:删除过程中会打印信息 >>> al ...
- 中文代码示例之Vuejs入门教程(一)
原址: https://zhuanlan.zhihu.com/p/30917346 为了检验中文命名在主流框架中的支持程度, 在vuejs官方入门教程第一部分的示例代码中尽量使用了中文命名. 所有演示 ...
- 微信小程序语音识别开发过程记录 微信小程序silk转mp3 silk转wav 以及ffmpeg使用
说说最近在开发微信小程序语音识别遇到的问题吧 最先使用微信小程序录音控件可以拿到silk格式,后来微信官方又支持mp3格式了 但是我们拿到这些格式以后,都还不能直接使用,做语音识别,因为目前百度的语音 ...
- Xamarin安卓开发:去掉Activity的头部标题栏及全屏显示
http://blog.csdn.net/u012234115/article/details/35814209 以下是用修改布局文件的方法,其实还有用C#代码的方法. 打开AndroidManife ...
- Flask-配置与调试
配置管理 复杂的项目需要配置各种环境.如果设置项很少,可以直接硬编码进来,比如下面的方式: app = Flask(__name__) app.config['DEBUG'] = True app.c ...
- Vue 爬坑之路(九)—— 用正确的姿势封装组件
迄今为止做的最大的 Vue 项目终于提交测试,天天加班的日子终于告一段落... 在开发过程中,结合 Vue 组件化的特性,开发通用组件是很基础且重要的工作 通用组件必须具备高性能.低耦合的特性 为了满 ...
- Jenkins 学习笔记(三):我们的JAVA 项目是这么发布的
发布拓扑 1. 拓扑图 2. 流程说明: Git 插件从 Git Server 上面拉取源代码. Maven 插件将源代码安装我们设定的指令进行编译打包,存放于项目的 WorkSpace. Publi ...
- 抽象方法为什么不能被private与static修饰
private private访问修饰符修饰的方法只能在本类当中使用.所以,必然不能用private去修饰抽象方法.抽象方法一定是要被子类去重写的. static Java中用static修饰符修饰的 ...