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 ...
随机推荐
- GitLab版本管理工具
第1章 GitLab管理 1.1 版本控制系统 版本控制系统(version control system)是记录一个或若干文件内容变化,以便将来查阅特定版本修订情况的系统.版本控制系统不仅可以应用于 ...
- MySQL 如何执行关联查询
本文同时发表在https://github.com/zhangyachen/zhangyachen.github.io/issues/51 当前mysql执行的策略很简单:mysql对任何关联都执行嵌 ...
- [置顶]
xamarin android自定义标题栏(自定义属性、回调事件)
自定义控件的基本要求 这篇文章就当是自定义控件入门,看了几篇android关于自定义控件的文章,了解了一下,android自定义控件主要有3种方式: 自绘控件:继承View类,所展示的内容在OnDra ...
- 栈详解及java实现
导读 栈和队列是有操作限制的线性表. 目录 1.栈的概念.特点.存储结构. 2.栈的java实现及运用. 概念 栈是一种只允许在一端进行插入或删除的线性表. 1.栈的操作端通常被称为栈顶,另一端被称为 ...
- es6 let和const命令(1)
基本用法 ES新增了let命令,用于声明变量.其用法类似于var,但是所声明的变量只在let命令所在的代码块中有效. for(let i = 0;i<5;i++) {} console.log( ...
- Python:监控ASM剩余空间
#!/usr/bin/env python # -*- coding:utf-8 -*- __author__ = 'Jipu FANG' version = 0.1 import cx_Oracle ...
- python:发送消息给微信企业号
# -*- coding:utf-8 -*- import requests import json ''' 基础环境:微信企业号 version:python 2.7 ''' class Send_ ...
- python 中一些关键字的区别
一.raw_input 和input input和raw_input都可以读取控制台的输入,但是input和raw_input在处理数字时是有区别的 1.当输入为纯数字时 input返回的是数值类型, ...
- Python Tkinter模块 Grid(grid)布局管理器参数详解
在使用Tkinter模块编写图像界面时,经常用到pack()和grid()进行布局管理,pack()参数较少,使用方便,是最简单的布局,但是当控件数量较多时,可能需要使用grid()进行布局(不要在同 ...
- 阿里云ECS搭建SVN配置外网
阿里云ECS搭建SVN后,配置外网启动不了,检查云服务器没发现问题,后来发现是阿里云拦截,需要在阿里云控制台ECS安全组新增如下配置: