Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

附上源代码,想法学习自《剑指offer》

Posted by gougoustudy at 2014-07-20 16:32:34 on Problem 2545
import java.util.Scanner;

public class Main{

	static void compute(int p1, int p2, int p3, int n) {
		long[] A = new long[n + 1];
		A[0] = 1;
		int x, y, z;
		x = y = z = 0;

		for(int i=1;i<=n;i++) {
			A[i]=minValue(A[x]*p1,A[y]*p2,A[z]*p3);
			while(A[x]*p1<=A[i]) {
				x++;
			}
			while(A[y]*p2<=A[i]) {
				y++;
			}
			while(A[z]*p3<=A[i]) {
				z++;
			}
		}
		System.out.println(A[n]);
	}

	static long minValue(long a, long b, long c) {
		long min = a > b ? b : a;
		return (min > c ? c : min);
	}

	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		int p1 = cin.nextInt();
		int p2 = cin.nextInt();
		int p3 = cin.nextInt();
		int n = cin.nextInt();

		compute(p1, p2, p3, n);

	}

}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator