POJ 1840.Eqs

Source: Internet
Author: User

Eqs Time limit:5000MS Memory Limit:65536KB 64bit IO Format:%i64d &%i64 U Submit Status Practice POJ 1840

Description

Consider equations has the following form:
a1x1 a2x2 a3x3, a4x4, a5x5 3=0
The coefficients is 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.

Input

The only line of input contains the 5 coefficients a1, A2, A3, A4, A5, separated by blanks.

Output

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

Sample Input

37 29 41) 43 47

Sample Output

654

Solve the five-yuan three-quadratic equation.

Brute Force hack

Enumerates all the possibilities.

Direct violence takes a lot of time 1005=1010

You can move a part to the other side with a1x13+a2x23=-(A3X33+A4X43+A5X53)

The time it takes to become 1002+1003 is a lot less order of magnitude.

The case to the left of the equation is enumerated in the right side of the enumeration equation.

Use an array to store the number of steps to the left to derive a numeric value, which is a viable solution if the number is reached on the right side of the equation.

Because of the huge data involved, the array can be opened into unsigned char to save

AC Code: GITHUB

1 /*2 By:ohyee3 Github:ohyee4 Homepage:http://www.oyohyee.com5 email:[email protected] ' e.com6 Blog:http://www.cnblogs.com/ohyee/7 8 かしこいかわいい? 9 エリーチカ! Ten to write out the хорошо code OH ~ One */ A  -#include <cstdio> -#include <algorithm> the#include <cstring> -#include <cmath> -#include <string> -#include <iostream> +#include <vector> -#include <list> +#include <queue> A#include <stack> at#include <map> - using namespacestd; -  - //DEBUG MODE - #defineDebug 0 -  in //Loops - #defineREP (n) for (int o=0;o<n;o++) to  + Const intMAXN =6250001*5; -UnsignedCharcnt[maxn*2]; the  * BOOLDo () { $     inta[5];Panax NotoginsengREP (5) -         if(SCANF ("%d", &a[o]) = =EOF) the             return false; +  Amemset (CNT,0,sizeof(CNT)); the  +     //Map<long long,int> m; -      for(inti =- -; I <= -; i++) $          for(intj =- -; J <= -; j + +) $             if(I! =0&& J! =0) { -                 Long Longtemp = MAXN + a[0] * i*i*i + a[1] * j*j*J; -cnt[temp]++; the             } - Wuyi     intAns =0; the      for(inti =- -; I <= -; i++) -          for(intj =- -; J <= -; j + +) Wu              for(intK =- -; K <= -; k++) -                 if(I! =0&& J! =0&& k! =0) { About                     Long Longtemp = MAXN-(a[2] * i*i*i + a[3] * j*j*j + a[4] * k*k*k); $Ans + =Cnt[temp]; -                 } -  -printf"%d\n", ans); A     return true; + } the  - intMain () { $      while(Do ()); the     return 0; the}

POJ 1840.Eqs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.