脚本宝典收集整理的这篇文章主要介绍了Comp20211218,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
import com.sun.tools.javac.util.Assert;import com.sun.tools.javac.util.Pair;import javax.jws.SOAp.SOAPBinding;import javax.swing.text.htML.Option;import java.lang.reflect.Field;import java.util.*;import java.util.stream.Stream;/*aabaacabaac4a.aa*caa.ba*bb*a */public class Main { PRivate static boolean beFound = false; private static boolean meetStart = false; private static void resolve(int[][] dp, int x, int y, String raw, String pat, boolean isMatched) { int row = pat.length(); int col = raw.length(); if (x + 1 < row) { if (pat.charAt(x + 1) == '*') { meetStart = true; if (x + 1 == row - 1) { System.out.println(dp[x][y] + " " + (y + 1)); beFound = true; return; } if (y > 0 && dp[x + 1][y] > 0) { return; } int weight = dp[x][y]; int temp = y; while (temp < col) { dp[x + 1][temp] = weight; resolve(dp, x + 1, temp, raw, pat, isMatched); if (beFound) { return; } temp ++; } } else { if (!isMatched) { if (pat.charAt(x) == '*' && (pat.charAt(x + 1) == '.' || pat.charAt(x + 1) == raw.charAt(y))) { if (y > 0 && dp[x + 1][y] > 0) { return; } dp[x + 1][y] = dp[x][y]; resolve(dp, x + 1, y, raw, pat, true); } } else if (y + 1 < col) { if (pat.charAt(x + 1) == '.' || pat.charAt(x + 1) == raw.charAt(y + 1)) { if (y > 0 && dp[x + 1][y + 1] > 0) { return; } dp[x + 1][y + 1] = dp[x][y]; if (x + 1 == row - 1) { System.out.println(dp[x][y] + " " + (y + 2)); beFound = true; return; } resolve(dp, x + 1, y + 1, raw, pat, true); } } } } } public static void main(String[] args) throws ClassNotFoundException { Scanner cn = new Scanner(System.in); String raw = cn.nextLine(); int cnt = Integer.parseInt(cn.nextLine()); for (int i = 0; i < cnt; i++) { String pat = cn.nextLine(); int row = pat.length(); int col = raw.length(); int[][] dp = new int[row][col]; beFound = false; meetStart = false; for (int n = 0; n < col; n++) { if (pat.charAt(0) == '.' || pat.charAt(0) == raw.charAt(n)) { dp[0][n] = n + 1; } if (pat.charAt(0) == '*') { dp[0][n] = 1; } } boolean matched = pat.charAt(0) != '*'; for (int m = 1; m < row; m++) { if (dp[m-1][0] == 0) { break; } if (pat.charAt(m) == '*') { dp[m][0] = dp[m-1][0]; } if (pat.charAt(m-1) == '*' && !matched && (pat.charAt(m) == '.' || pat.charAt(m) == raw.charAt(0))) { matched = true; dp[m][0] = dp[m-1][0]; } } if (dp[row - 1][0] > 0) { System.out.println("1 1"); continue; } for (int n = 0; n < col; n++) { if (dp[0][n] > 0) { System.out.println("meet"); resolve(dp, 0, n, raw, pat, pat.charAt(0) != '*'); if (beFound || meetStart) { break; } } } if (!beFound) { System.out.println("0 0"); } } }}
以上是脚本宝典为你收集整理的Comp20211218全部内容,希望文章能够帮你解决Comp20211218所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。