发现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. 【HTML5】HTML5新布局元素

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  2. JavaWeb 例子 JDBC+JSP登陆注册留言板

    注册页面: <%@ page language="java" contentType="text/html; charset=UTF-8" pageEnc ...

  3. DataBase MongoDB基础知识记录

    MongoDB基础知识记录 一.概念: 讲mongdb就必须提一下nosql,因为mongdb是nosql的代表作: NoSQL(Not Only SQL ),意即“不仅仅是SQL” ,指的是非关系型 ...

  4. sqlserver 存储过程 增加

    CREATE PROCEDURE [dbo].[InsertMessage]( @strTable varchar(), --表名 @strValues nvarchar(), --要插入的数据(用英 ...

  5. jquery如此强大,为什么还要写原生呢?

    这是一个伪标题,其实是一篇年终总结. 在这家公司一年多,蛮多收获的.大部分来自自己,小部分来自公司. 做前端开发到现在,我觉得可以分为两部分. 前半部分做项目用原生js,jquery以及各种基于jq的 ...

  6. KVO的内部实现以及使用

    转载自:http://www.cocoachina.com/applenews/devnews/2014/0107/7667.html   KVO是实现Cocoa Bindings的基础,它提供了一种 ...

  7. Hive实际应用小结

    1.简介 Hive是数据仓库平台,构建在Hadoop之上用来处理结构化数据.Hive是一个SQL解析引擎,能够将SQL语句转化成MapReduce作业并在Hadoop上执行,从而使得查询和分析更加方便 ...

  8. 未来五年什么样的IT技术最具颠覆性?这里有你想知道的答案

    据外媒报道称,近日Gartner研讨会在美国弗罗里达州奥兰多举行,智能化.大数据和物联网成为届研讨会的三大主题.市场研究机构Gartner Research的副总裁兼资深研究员大卫·卡利(David ...

  9. locust 参数,数据详解

    参数    说明-h, –help    查看帮助-H HOST, –host=HOST    指定被测试的主机,采用以格式:http://10.21.32.33–web-host=WEB_HOST  ...

  10. Webpack 2 视频教程 019 - Webpack 2 中配置多页面编译

    原文发表于我的技术博客 这是我免费发布的高质量超清「Webpack 2 视频教程」. Webpack 作为目前前端开发必备的框架,Webpack 发布了 2.0 版本,此视频就是基于 2.0 的版本讲 ...