POJ1068
来源:互联网 发布:我的世界天堂js怎么去 编辑:程序博客网 时间:2024/05/22 06:22
题目:http://acm.pku.edu.cn/JudgeOnline/problem?id=1068
思路:普通做法,构造出括号的数组,依次查找。。。
- import java.util.Scanner;
- public class Main {
- int t;
- int len;
- int[] p;
- int[] w;
- String[] s;
- int index;
- int temp;
- int pos;
- public Main() {
- Scanner scan = new Scanner(System.in);
- t = scan.nextInt();
- for (int i = 0; i < t; i++) {
- len = scan.nextInt();
- p = new int[len];
- w = new int[len];
- s = new String[len * 2];
- for (int j = 0; j < len; j++) {
- p[j] = scan.nextInt();
- }
- pos = 0;
- temp = 0;
- index = 0;
- for (int k = 0; k < len; k++) {
- for (; pos < p[k]; pos++) {
- s[index++] = "(";
- }
- s[index++] = ")";
- }
- search();
- for (int m = 0; m < len; m++) {
- System.out.print(w[m] + " ");
- }
- System.out.println();
- }
- }
- public void search() {
- pos = 0;
- int k = 0;
- for (int i = 0; i < len; i++) {
- for (; k < 2 * len; k++) {
- if (s[k].equals(")")) {
- pos = k;
- k++;
- break;
- }
- }
- temp = 0;
- index = 1;
- for (int j = pos - 1;; j--) {
- if (s[j].equals("(")) {
- temp++;
- index--;
- } else {
- index++;
- }
- if (index == 0) {
- w[i] = temp;
- break;
- }
- }
- }
- }
- public static void main(String[] args) {
- new Main();
- }
- }
- POJ1068
- POJ1068
- Poj1068
- poj1068
- poj1068
- poj1068
- poj1068
- poj1068
- poj1068
- poj1068
- POJ1068
- poj1068
- poj1068
- poj1068
- POJ1068
- poj1068
- poj1068
- poj1068
- [轉貼]驗證碼識別的基本思路及方法
- CheckBoxList单项控制
- Delphi流操作技巧
- 从tomcat到glashfish(glassfish的安装启动笔记)
- C# 用ListView控件多个选中并进行删除
- POJ1068
- 用 GlassFish v2 替换 Tomcat 5.x
- Windows下全新安装Glassfish服务器
- GlassFish:Java社区的水晶鱼
- Glassfish初试
- GlassFish FAQ
- 在Glassfish上部署web应用
- 在Eclipse下调试GlassFish程序
- QQ空间