发现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的更多相关文章

  1. [转]NLP Tasks

    Natural Language Processing Tasks and Selected References I've been working on several natural langu ...

  2. 2016.11.14 MIT challenge之课程总览

    Degree Chartshttp://catalog.mit.edu/degree-charts/computer-science-engineering-course-6-3/ MIT Chall ...

  3. 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 ...

  4. codechef May Challenge 2016 CHSC: Che and ig Soccer dfs处理

    Description All submissions for this problem are available. Read problems statements in Mandarin Chi ...

  5. codechef May Challenge 2016 FORESTGA: Forest Gathering 二分

    Description All submissions for this problem are available. Read problems statements in Mandarin Chi ...

  6. codechef May Challenge 2016 LADDU: Ladd 模拟

    All submissions for this problem are available. Read problems statements in Mandarin Chinese, Russia ...

  7. 深圳 Maker Faire 2016 & Microsoft Booth

    首先,感谢Hackster.io和微软,因为发表在Hackster.io的项目<A fall detection system based on Arduino, Windows and Azu ...

  8. (转) Summary of NIPS 2016

    转自:http://blog.evjang.com/2017/01/nips2016.html           Eric Jang Technology, A.I., Careers       ...

  9. python 2016 大会 pyconsk ppt ---python dtrace

    https://github.com/pyconsk/2016-slides PyCon SK 2016 - March 2016 1DTrace and PythonJesús Cea Aviónj ...

随机推荐

  1. rwx读写执行对文件和目录的意义

    文件 目录 r 查看 列出目录内容 w 修改 在目录内新建删除文件 x 执行 可以进入目录 对文件的删除权限是对文件所有目录的写权限 对目录-wx的权限,有写和执行权限,既可以在目录内创建删除文件,可 ...

  2. iOS Xcode及模拟器SDK下载

    原文: Xcode及模拟器SDK下载 如果你嫌在 App Store 下载 Xcode 太慢,你也可以选择从网络上下载: Xcode下载(Beta版打的包是不能提交到App Store上的) 绝对官方 ...

  3. iOS 网络监听、判断

    一 网络监听 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary ...

  4. nodejs+mongodb+vue前后台配置ueditor

    笔者在做一个个人博客项目的时候需要一个富文本框输入组件与后台进行交互,但是官方配置里面没有关于nodejs的,于是自己查阅资料研究了一下,最后终于应用到了系统中. 一.后台配置 首先是找到了这个项目: ...

  5. JavaSE项目之聊天室

    引子: 当前,互联网 体系结构的参考模型主要有两种,一种是OSI参考模型,另一种是TCP/IP参考模型. 一.OSI参考模型,即开放式通信系统互联参考模型(OSI/RM,Open Systems In ...

  6. 二分查找(折半查找)C++

    二分查找又称折半查找,优点是比较次数少,查找速度快,平均性能好,占用系统内存较少: 其缺点是要求待查表为有序表,且插入删除困难. 因此,折半查找方法适用于不经常变动而查找频繁的有序列表. 首先,假设表 ...

  7. split 命令详解

    作用:将大文件切割成小文件. 参数:-l 按照行数分隔文件       -b 按照大小分隔文件       -d 使用数字做后缀 实例:分隔文件默认1000行     split mylog ; wc ...

  8. mysql 编写存储过程

    先看例子: 1.delimiter $$2.drop procedure if exists`test_procedure` $$3.create procedure test_procedure(I ...

  9. 阿里云Centos7 apache配置

    其实很简单,主要是有坑. 首先填坑,在阿里云安全策略上开放要访问的端口,然后配置firewall添加对应端口开放. firewall-cmd --zone=public --add-port=8011 ...

  10. Xamarin.Android 怎么定义一个按钮和返回键功能一样回到上一个界面

    https://zhidao.baidu.com/question/570934367.html页面之间的跳转有startActivity 和startActivityForResult两种,star ...