首页 > 数据结构 > Hash表 > POJ 1840 Eqs [解题报告] Java
2013
11-10

POJ 1840 Eqs [解题报告] Java

Eqs

问题描述 :

Consider equations having the following form:

a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0

The coefficients are given integers from the interval [-50,50].

It is consider a solution a system (x1, x2, x3, x4, x5) that verifies the equation, xi∈[-50,50], xi != 0, any i∈{1,2,3,4,5}.

Determine how many solutions satisfy the given equation.

输入:

The only line of input contains the 5 coefficients a1, a2, a3, a4, a5, separated by blanks.

输出:

The output will contain on the first line the number of the solutions for the given equation.

样例输入:

37 29 41 43 47

样例输出:

654

解题代码:

//* @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];           //存立方数字的   
    int pos = 0;   
    int m = 0;            
    for (int x = -50; x <= 50; x++) {   
        if(x == 0) continue;         //为了删除掉0 不然会多出来200个解   
        bigsqure[m++] = x*x*x;       //把这个立方值存起来,以后好用。   
    }   
       
    //算出左边值   
    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”累加起来   
                //即是结果。   
            }   
        }   
    }   
        
  return answer;
 }  
}

  1. Hello Web Admin, I noticed that your On-Page SEO is is missing a few factors, for one you do not use all three H tags in your post, also I notice that you are not using bold or italics properly in your SEO optimization. On-Page SEO means more now than ever since the new Google update: Panda. No longer are backlinks and simply pinging or sending out a RSS feed the key to getting Google PageRank or Alexa Rankings, You now NEED On-Page SEO. So what is good On-Page SEO?First your keyword must appear in the title.Then it must appear in the URL.You have to optimize your keyword and make sure that it has a nice keyword density of 3-5% in your article with relevant LSI (Latent Semantic Indexing). Then you should spread all H1,H2,H3 tags in your article.Your Keyword should appear in your first paragraph and in the last sentence of the page. You should have relevant usage of Bold and italics of your keyword.There should be one internal link to a page on your blog and you should have one image with an alt tag that has your keyword….wait there's even more Now what if i told you there was a simple WordPress plugin that does all the On-Page SEO, and automatically for you? That's right AUTOMATICALLY, just watch this 4minute video for more information at.