跳到主要內容

發表文章

目前顯示的是 5月, 2015的文章

UVA10405

UVA10405 URL :  http://uva.onlinejudge.org/external/104/10405.pdf 基礎LCS ------------------------------------------------------------------------------------------ import java.util.Scanner; public class UVA10405 { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); while(sc.hasNext()) { String s1 = sc.nextLine(); String s2 = sc.nextLine(); char[] c1 = new char[s1.length()+1]; char[] c2 = new char[s2.length()+1]; for(int s =1;s<s1.length()+1;s++) { c1[s] = s1.charAt(s-1); } for(int s =1;s<s2.length()+1;s++) { c2[s] = s2.charAt(s-1); } int matrix[][] = new int[1001][1001]; int max = 0; for(int n = 1;n<s1.length()+1;n++) { for(int m = 1;m<s2.length()+1;m++) { if(c1[n] == c2[m]) matrix[n][m] = matrix[n-1][m-1] + 1; else matrix[n][m] = Math.max(matrix[n-1][

UVA534

UVA534 URL: http://uva.onlinejudge.org/external/5/534.pdf -------------------------------------------------------------- 大意 : 有隻青蛙想從A點跳到B點,問你A到B的路徑裡,最短的路徑裡權重最大的邊(最小生成樹的瓶頸) EX: path(start,2) = 3,path(2,3) =4 ,path(4,end) = 1 ,the distance is 4. -------------------------------------------------------------- import java.util.*; class undirected_graph { static double map[][] = new double[205][205]; static boolean visit[] = new boolean[205]; static double cost[] = new double[205]; static int parent[] = new int[205]; static int n = 0; void create_map(){ Scanner sc = new Scanner(System.in); int count =1; while(sc.hasNext()) { double map[][] = new double[205][205]; boolean visit[] = new boolean[205]; double cost[] = new double[205]; int parent[] = new int[205]; n = sc.nextInt(); sc.nextLine(); if(n==0)break; System.out.println("Scenario #"+count); int x_l[] = new int[n]; int y