# POJ 刷题系列：1068. Parencodings

### 题意：

```import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Map;
import java.util.StringTokenizer;

public class Main{

String INPUT = "./data/judge/201712/P1068.txt";

public static void main(String[] args) throws IOException {
new Main().run();
}

int t = ni();
while (t --> 0) {
int n = ni();
int[] p = new int[n];
for (int i = 0; i < n; ++i) {
p[i] = ni();
}
StringBuilder sb = new StringBuilder();
int pre = 0;
for (int i = 0; i < n; ++i) {
int cnt = p[i] - pre;
for (int j = 0; j < cnt; ++j) {
sb.append("(");
}
sb.append(")");
pre = p[i];
}

char[] cs = sb.toString().toCharArray();
int[] w = new int[n];
int[] stack = new int[cs.length + 16];
int tot = 0;
int k = 0;
for (int i = 0; i < cs.length; ++i) {
if (cs[i] == '(') {
stack[tot++] = i;
}
else {
w[k++] = (i - stack[tot - 1] + 1) / 2;
tot --;
}
}

for (int i = 0; i < n; ++i) {
out.print(w[i] + (i + 1 == n ? "\n" : " "));
}
}
}

FastScanner in;
PrintWriter out;

void run() throws IOException {
boolean oj;
try {
oj = ! System.getProperty("user.dir").equals("F:\\oxygen_workspace\\Algorithm");
} catch (Exception e) {
oj = System.getProperty("ONLINE_JUDGE") != null;
}

InputStream is = oj ? System.in : new FileInputStream(new File(INPUT));
in = new FastScanner(is);
out = new PrintWriter(System.out);
long s = System.currentTimeMillis();
out.flush();
if (!oj){
System.out.println("[" + (System.currentTimeMillis() - s) + "ms]");
}
}

public boolean more(){
return in.hasNext();
}

public int ni(){
return in.nextInt();
}

public long nl(){
return in.nextLong();
}

public double nd(){
return in.nextDouble();
}

public String ns(){
return in.nextString();
}

public char nc(){
return in.nextChar();
}

class FastScanner {
StringTokenizer st;
boolean hasNext;

public FastScanner(InputStream is) throws IOException {
hasNext = true;
}

public String nextToken() {
while (st == null || !st.hasMoreTokens()) {
try {
} catch (Exception e) {
hasNext = false;
return "##";
}
}
return st.nextToken();
}

String next = null;
public boolean hasNext(){
next = nextToken();
return hasNext;
}

public int nextInt() {
if (next == null){
hasNext();
}
String more = next;
next = null;
return Integer.parseInt(more);
}

public long nextLong() {
if (next == null){
hasNext();
}
String more = next;
next = null;
return Long.parseLong(more);
}

public double nextDouble() {
if (next == null){
hasNext();
}
String more = next;
next = null;
return Double.parseDouble(more);
}

public String nextString(){
if (next == null){
hasNext();
}
String more = next;
next = null;
return more;
}

public char nextChar(){
if (next == null){
hasNext();
}
String more = next;
next = null;
return more.charAt(0);
}
}

static class D{

public static void pp(int[][] board, int row, int col) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < row; ++i) {
for (int j = 0; j < col; ++j) {
sb.append(board[i][j] + (j + 1 == col ? "\n" : " "));
}
}
System.out.println(sb.toString());
}

public static void pp(char[][] board, int row, int col) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < row; ++i) {
for (int j = 0; j < col; ++j) {
sb.append(board[i][j] + (j + 1 == col ? "\n" : " "));
}
}
System.out.println(sb.toString());
}
}

static class ArrayUtils {

public static void fill(int[][] f, int value) {
for (int i = 0; i < f.length; ++i) {
Arrays.fill(f[i], value);
}
}

public static void fill(int[][][] f, int value) {
for (int i = 0; i < f.length; ++i) {
fill(f[i], value);
}
}

public static void fill(int[][][][] f, int value) {
for (int i = 0; i < f.length; ++i) {
fill(f[i], value);
}
}
}

static class Num{
public static <K> void inc(Map<K, Integer> mem, K k) {
if (!mem.containsKey(k)) mem.put(k, 0);
mem.put(k, mem.get(k) + 1);
}
}
}```

98 篇文章33 人订阅

0 条评论

## 相关文章

3054

722

36010

### salesforce 零基础开发入门学习（七）PickList的value值获取

之前介绍过PickList类型的声明以及赋值，但是如何取出呢?一个sObject对象可以理解为一条数据。通过sObject直接取恐怕很难做到，因为他只会...

1935

1888

3125

### 《笨办法学Python》 第4课手记

《笨办法学Python》 第4课手记 这节课目的是让你掌握变量，跟C语言非常类似，很简单。 左边是变量名用”=”号给变量赋值。 不同的是我没有看到变量声明，作者...

1678

702

3115

### 【超全】C语言小白最容易犯的17种错误，你中了几个？

C编译的程序对语法检查并不像其它高级语言那么严格，这就给编程大佬们留下了“灵活的余地”，但还是由于这个灵活给程序的调试带来了许多不便，尤其对刚刚接触C语言的人来...

3355