Java 过水题系列。
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1407
import java.io.*;
import java.math.*;
import java.util.*;
public class Main{
public static void main(String argv[]){
Scanner cin = new Scanner(System.in);
int [] a = new int[10005];
int [] routei = new int[10005];
int [] routej = new int[10005];
int [] routek = new int[10005];
int [] b = new int[105];
for(int i = 1 ; i <= 100 ; i++) {
b[i] = i * i;
}
for(int i = 1 ; i <= 10000 ; i ++) a[i] = 0;
for(int i = 1 ; i <= 100 ; i++) {
for(int j = i ; j <= 100 ; j ++) {
if(b[i] + b[j] > 10000) break;
for(int k = j ; k <= 100 ; k++) {
if(b[i] + b[j] + b[k] > 10000) break;
if(a[b[i] + b[j] + b[k]] == 1) continue;
a[b[i]+b[j]+b[k]] = 1;
routei[b[i]+b[j]+b[k]] = i;
routej[b[i]+b[j]+b[k]] = j;
routek[b[i]+b[j]+b[k]] = k;
}
}
}
int n ;
while(cin.hasNext()){
n = cin.nextInt();
System.out.printf("%d %d %d\r\n",routei[n],routej[n],routek[n]);
}
}
}