| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
附上源代码,想法学习自《剑指offer》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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator