2013
11-13

# Repeater

Harmony is indispensible in our daily life and no one can live without it—-may be Facer is the only exception. One day it is rumored that repeat painting will create harmony and then hundreds of people started their endless drawing. Their paintings were based on a small template and a simple method of duplicating. Though Facer can easily imagine the style of the whole picture, but he cannot find the essential harmony. Now you need to help Facer by showing the picture on computer.

You will be given a template containing only one kind of character and spaces, and the template shows how the endless picture is created—-use the characters as basic elements and put them in the right position to form a bigger template, and then repeat and repeat doing that. Here is an example.

# #
#      <-template
# #

So the Level 1 picture will be

# #
#
# #

Level 2 picture will be


# #   # #
#     #
# #   # #
# #
#
# #
# #   # #
#     #
# #   # #
 
 输入: The input contains multiple test cases.The first line of each case is an integer N, representing the size of the template is N*N (N could only be 3, 4 or 5).Next N lines describe the template.The following line contains an integer Q, which is the Scale Level of the picture.Input is ended with a case of N=0.It is guaranteed that the size of one picture will not exceed 3000*3000. 输出: For each test case, just print the Level Q picture by using the given template. 样例输入: 3 # # # # # 1 3 # # # # # 3 4 OO O O O O OO 2 0 样例输出: # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # OO OO O OO O O OO O OO OO OO OO O O O O O O O O OO OO OO OO O O O O O O O O OO OO OO OO O OO O O OO O OO OO 提交代码  问题讨论  数据统计 解题代码: import java.util.Scanner; public class Main { 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[n]; 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(); } } } (adsbygoogle = window.adsbygoogle || []).push({}); window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"24"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)]; 
 
 Java ⇐ POJ 3767 I Wanna Go Home [解题报告] Java POJ 3845 Fractal [解题报告] Java ⇒ 您可能还会对这些文章感兴趣！ HDU 1063 Exponentiation-高精度-[解题报告] java HDU 1038 Biker’s Trip Odometer-Java-[解题报告] java HDU 1023 Train Problem II-高精度-[解题报告] java HDU 1018 Big Number-高精度-[解题报告] C++ POJ 3984 迷宫问题 [解题报告] Java POJ 3982 序列 [解题报告] Java POJ 3979 分数加减法 [解题报告] Java POJ 3895 Cycles of Lanes [解题报告] Java if (typeof DUOSHUO !== 'undefined') DUOSHUO.EmbedThread('.ds-thread'); testnew on 2015年7月13日 at 下午4:31 said: 编辑的时候有些不小心了 huangdilj on 2015年3月6日 at 下午5:33 said: 不错，赞一个！ Supermaner on 2014年12月23日 at 下午7:26 said: 较好的写法是 start+(end-start)/2 oneal on 2014年9月20日 at 上午12:24 said: 根本过不了。。。。 becool456 on 2014年8月26日 at 上午8:50 said: 我又来学习了 wangzhenvs123 on 2014年8月3日 at 上午9:45 said: 不考虑最后将结果排序的话，快排的时间复杂度是O(N) ，而堆排的是O(N*logK) Dick on 2014年5月20日 at 下午12:36 said: 程序只能输出一个子序列 liluvu on 2014年4月22日 at 下午5:10 said: 这张页面太松散拉，重新编辑一下，弄紧凑一点。 fastislow on 2014年4月22日 at 上午3:35 said: 这是研发类的题还是算法类？ CCCat on 2014年3月15日 at 上午7:09 said: 感觉第二种方法其实也不是很好，不过的确要比第一种方法要好一点。 radish on 2014年3月14日 at 下午11:02 said: good !