parentheses

Longest `subsequence` of balanced parentheses

折月煮酒 提交于 2019-12-06 19:56:27
I am trying to solve a variant of a problem I asked earlier: Given a string of parentheses (length <= 1,000,000) and a list of range queries, find the longest subsequence of balanced parentheses within each of the ranges for each of the <= 100,000 queries I found this other SO question that is similar but only has an O(N^3) algorithm. I believe that a DP solution of the form dp[i, j] = longest balanced subsequence in [i .. j] should work because once computed, this would enable to to answer all of the range queries just by querying the DP table. However, even an O(N^2) solution to this problem

Java - parentheses and assignment

拟墨画扇 提交于 2019-12-06 08:59:02
The code: int r=1; System.out.println(r + (r=2)); The output is: 3. But I expected 4 because I thought the code inside the parentheses is executed first? Official Docs on Operators says All binary operators except for the assignment operators are evaluated from left to right; assignment operators are evaluated right to left. So + is evaluated left-to-right ,where as assignment operators are evaluated right to left. Use this if you want 4 int r=1; System.out.println((r=2) + r); // execute + is left-to-right Associativity of + is left-to-right , and the value of the expression (r=2) is 2 . Refer

How do I parenthesize an expression?

半腔热情 提交于 2019-12-06 08:17:09
问题 I have an idea for a simple program to make that will help me with operator precedence in languages like C. The most difficult part of this is parenthesizing the expression. For example, I want this: *a.x++ = *b.x++ Converted to this: ((*(((a).(x))++)) = (*(((b).(x))++))) Which I did manually in these steps: *a.x++ = *b.x++ *(a).(x)++ = *(b).(x)++ *((a).(x))++ = *((b).(x))++ *(((a).(x))++) = *(((b).(x))++) (*(((a).(x))++)) = (*(((b).(x))++)) ((*(((a).(x))++)) = (*(((b).(x))++))) What is the

Why does this triple quoting solution fix path error?

雨燕双飞 提交于 2019-12-06 05:53:05
So I was running into a bit of a problem today with this bit of code: os.system("C:\Program Files (x86)\DOSBox-0.72\dosbox.exe") Upon execution I'd get this error message: 'C:\Program' is not recognized as an internal or external command, operable program or batch file. I assumed it was something to do with either the white space or the brackets, so I did a bit of digging online and after countless of ineffective "solutions" involving escape characters, I ended up finding a rather strange solution; to surround the double quotes with another double and a single like so: os.system('""C:\Program

What is the intention of putting return values in parentheses in C/Objective-C?

耗尽温柔 提交于 2019-12-05 12:36:45
I've come across some code that surrounds the return value from a method/function in parentheses. What does that do? The code I saw took an image, resized it and then returned it. - (UIImage *)resizeImage:(UIImage *)image { // // some fascinating, but irrelevant, resizing code here // return (image); } At least as far as C is concerned, it makes no difference. The parens aren't necessary, but they don't change the meaning of the return statement. The grammar of the return statement is return-statement : return expression opt ; and one of the productions of the expression non-terminal is a

sqlalchemy how to using AND in OR operation?

淺唱寂寞╮ 提交于 2019-12-05 11:04:14
i need to do this query: SELECT * FROM tbl_member WHERE (member_type==1 AND member_status==1) OR (member_type==2 and member_status==2) i've tried: q=session.query(tbl_member) \ .filter(or_(and_(tbl_member.member_type==1,tbl_member.member_status==1), \ and_(tbl_member.member_type==2,tbl_member.member_status==2))) and q=session.query(tbl_member) \ .filter(or_((and_(tbl_member.member_type==1,tbl_member.member_status==1)), \ (and_(tbl_member.member_type==2,tbl_member.member_status==2)))) the query sql still like this: SELECT * FROM tbl_member WHERE member_type==1 AND member_status==1 OR member

How to set curly braces'/parentheses'/square brackets'/arithmetic operators' syntax highlight color in VIM?

坚强是说给别人听的谎言 提交于 2019-12-05 09:08:36
How do I highlight operators/parentheses/brackets/etc. in VIM? I'm not interested in coloring matching or unmatching parentheses/brackets. I've tried ":hi cBracket/whatnot guifg=something" and ":hi Operator/cOperator guifg=something" but these don't seem to affect anything. There are two parts to Vim syntax coloring: the syn command and the hi command. As far as I understand, you use syn to define syntax. For example: syn match parens /[(){}]/ Then you use hi to tell Vim how to highlight parens : hi parens ctermfg=red See :h pi_paren.txt about highlighting matching parens: To disable the

laravel - why function call with no parentheses?

核能气质少年 提交于 2019-12-05 01:28:15
I see this in a laravel tutorial : Auth::user()->item; where item is a function, inside models\User.php : function item() { return $this->hasMany('Item', 'owner_id'); } where Item is for models\Item.php So why the parentheses is not needed when item function is called ? Like : Auth::user()->item(); If I put the parentheses, the browsers goes crazy and crash. Also, if I rename Item.php to Item2.php, rename class Item to Item2, and I do hasMany('Item2', 'owner_id') , it won't work. But why ? Where does 'Item' came from ? Thanks, Patrick Laravel uses the magic function __get to handle arbitrary

How do I infer the usage of parentheses when translating an expression tree?

喜欢而已 提交于 2019-12-04 19:46:51
问题 I am working on translating an expression tree to a format that resembles infix notation; I am not evaluating the tree or executing its operations. The tree contains both logical and relational operations, and I would like to emit parentheses in an intelligent manner during the translation. To illustrate, consider the following contrived expression: a < x & (a < y | a == c) & a != d If I walk the expression tree produced by this expression in-order, then I will print out the following

A text editor that auto-folds parentheses?

巧了我就是萌 提交于 2019-12-04 18:45:16
I have some big messy SQL procedures that I'm debugging, and they tend to have a lot of heavily nested parentheses: SELECT * FROM (SELECT F1,F2 FROM TABLE1 AS X LEFT JOIN (SELECT F9,F8 FROM (SELECT F13,F14 FROM TABLE4) AS J INNER JOIN TABLE3 ON...) AS B ON X.F1=B.F9) AS X1 I'm looking for an editor that can automatically mark and optionally collapse/fold each parentheses set to ease reading, e.g. SELECT * FROM ... AS X1 SELECT * FROM (SELECT F1,F2 FROM TABLE1 AS X LEFT JOIN ... AS B ON X.F1=B.F9) AS X1 I can do this in Visual Studio by repeatedly hitting ctrl-shift-] to select a set, and then