Scaena Felix
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 182 Accepted Submission(s): 85
Problem Description
Given a parentheses sequence consist of '(' and ')', a modify can filp a parentheses, changing '(' to ')' or ')' to '('.
If we want every not empty <b>substring</b> of this parentheses sequence not to be "paren-matching", how many times at least to modify this parentheses sequence?
For example, "()","(())","()()" are "paren-matching" strings, but "((", ")(", "((()" are not.
If we want every not empty <b>substring</b> of this parentheses sequence not to be "paren-matching", how many times at least to modify this parentheses sequence?
For example, "()","(())","()()" are "paren-matching" strings, but "((", ")(", "((()" are not.
Input
The first line of the input is a integer T, meaning that there are T test cases.
Every test cases contains a parentheses sequence S only consists of '(' and ')'.
1≤|S|≤1,000.
Every test cases contains a parentheses sequence S only consists of '(' and ')'.
1≤|S|≤1,000.
Output
For every test case output the least number of modification.
Sample Input
3
()
((((
(())
Sample Output
1
0
2
Source
Recommend
模拟.
直接搞...
并不明白坑在哪里...
排在我前面被hack了100多人...

1 /************************************************************************* 2 > File Name: code/bc/#57/1001.cpp 3 > Author: 111qqz 4 > Email: rkz2013@126.com 5 > Created Time: 2015年09月26日 星期六 19时04分34秒 6 ************************************************************************/ 7 8 #include<iostream> 9 #include<iomanip> 10 #include<cstdio> 11 #include<algorithm> 12 #include<cmath> 13 #include<cstring> 14 #include<string> 15 #include<map> 16 #include<set> 17 #include<queue> 18 #include<vector> 19 #include<stack> 20 #include<cctype> 21 #define y1 hust111qqz 22 #define yn hez111qqz 23 #define j1 cute111qqz 24 #define ms(a,x) memset(a,x,sizeof(a)) 25 #define lr dying111qqz 26 using namespace std; 27 #define For(i, n) for (int i=0;i<int(n);++i) 28 typedef long long LL; 29 typedef double DB; 30 const int inf = 0x3f3f3f3f; 31 const int N=1E3+7; 32 char str[N]; 33 int len; 34 int main() 35 { 36 #ifndef ONLINE_JUDGE 37 freopen("in.txt","r",stdin); 38 #endif 39 int T; 40 cin>>T; 41 while (T--) 42 { 43 scanf("%s",str); 44 len = strlen(str); 45 int cnt = 0; 46 int ans = 0 ; 47 for ( int i = 0 ; i < len ; i++) 48 { 49 if (str[i]=='(') 50 { 51 cnt++; 52 } 53 else 54 { 55 cnt--; 56 if (cnt>=0) 57 { 58 ans++; 59 } 60 if (cnt<0) 61 cnt = 0 ; 62 } 63 } 64 printf("%d ",ans); 65 } 66 67 #ifndef ONLINE_JUDGE 68 fclose(stdin); 69 #endif 70 return 0; 71 }