poj 1840 哈希~~~

分成左右两个部分a1,a2和-a3,-a4,-a5

View Code
import java.io.*;
import java.util.*;
import java.math.*;
public class Main{
public static void main(String[] args){
Scanner cin = new Scanner (System.in);
int a1=cin.nextInt();
int a2=cin.nextInt();
int a3=cin.nextInt();
int a4=cin.nextInt();
int a5=cin.nextInt();
System.out.println(hashQuestions(a1,a2,a3,a4,a5));
}
public static int hashQuestions(int a1,int a2,int a3,int a4,int a5){
char hash[] = new char[25000010];
int bigs[] = new int[100];
int pos=0;
int m=0;
for(int x=-50;x<=50;x++){
if(x!=0) bigs[m++]=x*x*x;
}
for(int i=0;i<100;i++){
for(int j=0;j<100;j++){
pos=-(bigs[i]*a1+bigs[j]*a2);
hash[pos+12500000]++;
}
}
int ans=0;
for(int i=0;i<100;i++){
for(int j=0;j<100;j++){
for(int k=0;k<100;k++){
pos = bigs[i]*a3+bigs[j]*a4+bigs[k]*a5;
if(pos > 12500000 || pos < -12500000) continue;
ans+=hash[pos+12500000];
}
}
}
return ans;
}
}



posted @ 2011-12-22 12:24  Because Of You  Views(216)  Comments(0Edit  收藏  举报