L3-029 还原文件 (30 分)java版
题目分析:
一份重要文件被撕成两半,其中一半还被送进了碎纸机。我们将碎纸机里找到的纸条进行编号,如图 1 所示。然后根据断口的折线形状跟没有切碎的半张纸进行匹配,最后还原成图 2 的样子。要求你输出还原后纸条的正确拼接顺序。
图1 纸条编号
图2 还原结果
输入格式:
输入首先在第一行中给出一个正整数 N(1<N≤105),为没有切碎的半张纸上断口折线角点的个数;随后一行给出从左到右 N 个折线角点的高度值(均为不超过 100 的非负整数)。
随后一行给出一个正整数 M(≤100),为碎纸机里的纸条数量。接下去有 M 行,其中第 i 行给出编号为 i(1≤i≤M)的纸条的断口信息,格式为:
K h[1] h[2] ... h[K]
其中 K
是断口折线角点的个数(不超过 104+1),后面是从左到右 K
个折线角点的高度值。为简单起见,这个“高度”跟没有切碎的半张纸上断口折线角点的高度是一致的。
输出格式:
在一行中输出还原后纸条的正确拼接顺序。纸条编号间以一个空格分隔,行首尾不得有多余空格。
题目数据保证存在唯一解。
输入样例:
17
95 70 80 97 97 68 58 58 80 72 88 81 81 68 68 60 80
6
4 68 58 58 80
3 81 68 68
3 95 70 80
3 68 60 80
5 80 72 88 81 81
4 80 97 97 68
输出样例:
3 6 1 5 2 4
这边只有一个没过,不是很清楚,各位可以给点建议!!!
谢谢!!!
我觉得我的方法没啥问题奥!!!
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.*;
public class Main {
static class FastScanner {
BufferedReader buf;
StringTokenizer stk;
public FastScanner() {
buf = new BufferedReader(new InputStreamReader(System.in),16384);
eat("");
}
public void eat(String ss) {
stk = new StringTokenizer(ss);
}
public String nextLine() {
try {
return buf.readLine();
} catch (IOException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
return null;
}
}
public boolean hasNext() {
while(!stk.hasMoreTokens()) {
String ss = nextLine();
if(ss==null) {
return false;
}
eat(ss);
}
return true;
}
public String next() {
hasNext();
return stk.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public double nextDouble() {
return Double.valueOf(next());
}
}
static FastScanner in = new FastScanner();
public static void main(String[] args) {
// TODO 自动生成的方法存根
in.next();
String sa1 = in.nextLine();
StringBuilder sa = new StringBuilder(sa1);
int fa = in.nextInt();
DataL3[] da = new DataL3[fa];
// boolean[] bol = new boolean[fa];
for(int i=0;i<fa;i++) {
da[i] = new DataL3();
da[i].wei = i+1;
String temp = in.nextLine();
int tem = temp.indexOf(" ");
da[i].zhi = sa.indexOf(temp.substring(tem+1, temp.length()));
}
Arrays.sort(da);
for(int i=0;i<fa-1;i++) {
System.out.print(da[i].wei+" ");
}
System.out.println(da[fa-1].wei);
}
}
class DataL3 implements Comparable<DataL3>{
int wei;
int zhi;
@Override
public int compareTo(DataL3 o) {
// TODO 自动生成的方法存根
if(this.zhi>o.zhi) {
return 1;
}else if(this.zhi==o.zhi) {
return 0;
}
return -1;
}
}