poj 3768 解题报告
2010-05-12 19:36
411 查看
好久没做acm的题了,呵呵!最近做了一次poj的月赛,杯具,就只做起了两道题。现在发的这道题是一个模拟题poj3768,来看看这道题的题目意思吧:
就是题目给一个模板串,然后在给个重复的次数level。题意很简单。这道题就是个dfs思想,递归模拟。
我们来看看代码吧:
http://acm.pku.edu.cn/JudgeOnline/problem?id=3768
就是题目给一个模板串,然后在给个重复的次数level。题意很简单。这道题就是个dfs思想,递归模拟。
我们来看看代码吧:
package poj; import java.util.Scanner; public class Main3768 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNextInt()) { int n = sc.nextInt(); if (n == 0) break; sc.nextLine(); String[] template = new String ; for (int i = 0; i < n; ++i) { String s = sc.nextLine(); template[i] = new String(s); } // sc.nextLine(); // sc.nextLine(); int level = sc.nextInt(); copy(template, template, level); } } private static void copy(String[] template1, String[] template2, int level) { --level; if (level > 0) { int n1 = template1.length; int n2 = template2.length; String[] tmpTemplate = new String[n1 * n2]; int k = 0; String spaceS = spaceStr(n2); for (int i = 0; i < n1; ++i) { for (int j = 0; j < n1; ++j) { k = i * n2; if (template1[i].charAt(j) == ' ') { for (int x = 0; x < n2; ++x) { if (tmpTemplate[k] != null) tmpTemplate[k] += (spaceS); else tmpTemplate[k] = new String(spaceS); k++; } } else { for (int x = 0; x < n2; ++x) { if (tmpTemplate[k] != null) tmpTemplate[k] += template2[x]; else tmpTemplate[k] = template2[x]; k++; } } } // print(tmpTemplate); } copy(template1, tmpTemplate, level); } else print(template2); } private static String spaceStr(int n) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; ++i) { sb.append(" "); } return sb.toString(); } private static void print(String[] template) { int n = template.length; // System.out.println(n); for (int i = 0; i < n; ++i) { System.out.print(template[i]); System.out.println(); } } }
http://acm.pku.edu.cn/JudgeOnline/problem?id=3768
相关文章推荐
- POJ 1056 解题报告
- POJ 1423 解题报告
- POJ 2243解题报告
- poj 1026 解题报告
- POJ 4047 Garden (线段树 - 区间增减、区间查询) -- 解题报告
- POJ 2411 Mondriaan's Dream 解题报告【动态规划】(代码部分)
- poj解题报告——2299
- poj1905解题报告
- POJ3162 解题报告
- POJ-1861-Network 解题报告
- POJ 1045 解题报告
- POJ 3006 解题报告
- POJ 1146 解题报告
- KMP POJ 1961 Period 解题报告
- POJ1250解题报告
- POJ3619解题报告
- POJ3602解题报告
- POJ_1007:DNA Sorting解题报告
- POJ 1004(平均数) 解题报告
- poj 1195 Mobile phones 解题报告