跳到主要內容

發表文章

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...

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...

ITSA_38_Pro5

[Problem 5] Pseudo Random Generation 成績: 0 / 倒扣: 0.8 Problem Description Random numbers are usually used in computer program. Computer can't produce pure random numbers but can produce pseudo random numbers. There are some pseudo random generators in our program language library which are usually used. There is a method which is usually used to produce pseudo random numbers. The method is called linear congruential method. This method needs 4 parameters: m   a   c   X 0 a modulus   a multiplier   a addend   a initial number(seed number) m   > 0 0 <   a   <   m 0 ≤   c   <   m 0 ≤   X 0   <   m The pseudo random numbers are produced by follow program states:   X n +1   = (   aX n   +   c   ) mod   m   For example, if   a   = 7,   c   = 5,   m   =12, and   X 0   = 4 then the program produces ...

UVA11538

Link :  http://uva.onlinejudge.org/external/115/11538.pdf ----------------------------------------------------------------------------------------------------------- Hint :         ※ 假設M邊較長               總共有三種方法可以攻擊敵人,行、列、斜向。         行與列:         黑后有M*N種位置選擇,選擇M以後白后就只剩下N-1個位置,得 M*N(N-1),etc         得 N*M(M-1),整合為 N*M( N + M - 2) 。         斜向:最長的斜向一共有 M - N + 1條,假定最長斜向為 n length         可得1,2,3......n-1,nnnnnn(M-N+1條) ,n-1,n-2,.......1,令 1 ~ n-1 加總為 i         故可得一共有 2 *  ∑ i ( i-1 ) (1<= i <=n-1) 條斜向(不含最長)         最長的斜向:N ( N-1 ) ( M - N + 1) ,選了一個N即剩下N-1種選擇         斜向總數:( 2 *  ∑ i ( i - 1 ) (1<= i <=n-1) + N( N - 1 ) ( M - N + 1) )  * 2 (正反斜)                   ...

UVA409

  Excuses, Excuses!   Judge Ito is having a problem with people subpoenaed for jury duty giving rather lame excuses in order to avoid serving. In order to reduce the amount of time required listening to goofy excuses, Judge Ito has asked that you write a program that will search for a list of keywords in a list of excuses identifying lame excuses. Keywords can be matched in an excuse regardless of case. Input Input to your program will consist of multiple sets of data. Line 1 of each set will contain exactly two integers. The first number (   ) defines the number of keywords to be used in the search. The second number (   ) defines the number of excuses in the set to be searched. Lines 2 through  K +1 each contain exactly one keyword. Lines  K +2 through  K +1+ E  each contain exactly one excuse. All keywords in the keyword list will contain only contiguous lower case alphabetic characters of length  L  ( ...

UVA136

  Ugly Numbers   Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, ... shows the first 11 ugly numbers. By convention, 1 is included. Write a program to find and print the 1500'th ugly number. Input and Output There is no input to this program. Output should consist of a single line as shown below, with <number> replaced by the number computed. Sample output The 1500'th ugly number is <number>. ----------------------------------------------------------------------------------------------------- import java.util.HashSet; import java.util.PriorityQueue; import java.util.Set; public class Main{ public static void main(String[] args) { PriorityQueue<Long> pq = new PriorityQueue<Long>(); int[] store = new int[] { 2, 3, 5 }; Set st = new HashSet(); pq.offer((long) 1); st.add(1); for (int i = 1;; i++) { long num = pq.peek(); ...

UVA101

The Blocks Problem   Background   Many areas of Computer Science use simple, abstract domains for both analytical and empirical studies. For example, an early AI study of planning and robotics (STRIPS) used a block world in which a robot arm performed tasks involving the manipulation of blocks. In this problem you will model a simple block world under certain rules and constraints. Rather than determine how to achieve a specified state, you will ``program'' a robotic arm to respond to a limited set of commands. The Problem   The problem is to parse a series of commands that instruct a robot arm in how to manipulate blocks that lie on a flat table. Initially there are  n  blocks on the table (numbered from 0 to  n -1) with block  b i  adjacent to block  b i +1  for all   as shown in the diagram below:   Figure:  Initial Blocks World The valid commands for the robot arm that manipulates blocks are:...