Poj Solution 1840

http://poj.org/problem?id=1840

//* @author: 
import java.util.*;
public   class Main{    
   
    public static void main(String[] args) {
       Scanner sc=new Scanner(System.in);

       int a1=sc.nextInt();
       int a2=sc.nextInt();
       int a3=sc.nextInt();
       int a4=sc.nextInt();
       int a5=sc.nextInt();
      System.out.println( hashQuestions(a1,a2, a3,a4,a5));
  }
   
 
   /**  
    * @param a1  
    * @param a2  
    * @param a3  
    * @param a4  
    * @param a5  
    */  
   public static  int  hashQuestions(int a1, int a2, int a3, int a4, int a5){   
       
    char hash[] = new char[25000010];   //hash�洢   
       
    int bigsqure[] = new int[100];           //��b�����ֵ�   
    int pos = 0;   
    int m = 0;            
    for (int x = -50; x <= 50; x++) {   
        if(x == 0) continue;         //Ϊ��ɾ���0 ��Ȼ����4200���   
        bigsqure[m++] = x*x*x;       //�����b��ֵ����4���Ժ���á�   
    }   
       
    //������ֵ   
    for (int i = 0; i < 100; i++) {   
        for (int j = 0; j < 100; j++) {   
            pos = -(bigsqure[i]*a1 + bigsqure[j]*a2);      
                
            hash[pos+12500000]++;          //���ֵΪ1��!   
               
            //��������֮�� ��hash������������� ��������߽���Ԫ��  ֵ��Ϊ1�ˡ�   
        }   
    }   
       
    int answer = 0;   
    //���ұ�ֵ   
    for (int i = 0; i < 100; i++) {   
        for (int j = 0; j < 100; j++) {   
            for (int k = 0; k < 100; k++) {   
                pos = bigsqure[i]*a3 + bigsqure[j]*a4 + bigsqure[k]*a5;   
                if(pos > 12500000 || pos < -12500000)    
                    continue;   
                answer += hash[pos+12500000];   
                   
                //�����ӵĵ��?�ǣ�����ұߵ�ֵû�к�����ص� ��ô���ֵ��0��   
                //����ص��ˣ�����ߵ�ʱ�� �Ѿ�������Ϊ1�ˣ���ô �����е��ص��ġ�1���ۼ���4   
                //���ǽ��   
            }   
        }   
    }   
        
  return answer;
 }  
}
											
This entry was posted in poj. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *