ZOJ-1038
来源:互联网 发布:日本文化教育网络视频 编辑:程序博客网 时间:2024/04/27 22:51
高效的做法应该是用前缀树,这里我直接暴力枚举模拟了,也能过。。
import java.util.Map;import java.util.Scanner;import java.util.TreeMap;import java.util.regex.Pattern;public class Main{public static void main(String[] args){Scanner sc = new Scanner(System.in);String[] ps = new String[] { "", "", "[abc]", "[def]", "[ghi]","[jkl]", "[mno]", "[pqrs]", "[tuv]", "[wxyz]" };int N = sc.nextInt();Map<String, Integer> dict = new TreeMap<String, Integer>();String line;for (int t = 1; t <= N; t++){System.out.format("Scenario #%d:\n", t);dict.clear();int w = sc.nextInt();sc.nextLine();while (w-- > 0){line = sc.nextLine();String[] ss = line.split(" ");dict.put(ss[0], Integer.valueOf(ss[1]));}int m = sc.nextInt();sc.nextLine();while (m-- > 0){line = sc.nextLine();String pattern = "";for (int i = 0; i < line.length() - 1; i++){pattern += ps[line.charAt(i) - '0'];Pattern p = Pattern.compile(pattern);String curr, prev = null, res = null;int prob = 0, max = -1;for (String key : dict.keySet()){if (key.length() >= (i + 1)&& p.matcher(key.substring(0, i + 1)).find()){curr = key.substring(0, i + 1);if (curr.equals(prev))prob += dict.get(key);elseprob = dict.get(key);if (prob > max){max = prob;res = curr;}prev = curr;}}if (res != null)System.out.println(res);elseSystem.out.println("MANUALLY");}System.out.println();}System.out.println();}sc.close();}}
0 0
- ZOJ-1038
- zoj 1038 T9
- ZOJ 1038 - T9
- ZOJ 1038 T9
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- 《胭粉计》
- 使用eclipse自动生成build.xml文件
- hdu2196
- WPF技术触屏上的应用系列(四): 3D效果图片播放器(图片立体轮放、图片立体轮播、图片倒影立体滚动)效果实现
- 黑马程序员_三层架构之用户登陆(BS架构)
- ZOJ-1038
- Brackets Sequence - POJ 1141 dp
- 高斯分布
- JavaScript获取select下拉框中的第一个值
- STL multiset 学习(NYOJ-55 懒省事的小明)
- 《梅妃》
- Action访问Servlet API
- 吐槽HDOJ 1002
- 究竟什么是敏捷软件测试?