Equations
Test instructions: Given a coefficient of two times for a four-yuan equation a,b,c,d; ask how many solutions;
A, B, C, D is integers from the interval [ -50,50] and any of them cannot is 0.
It is consider a solution a system (X1,X2,X3,X4) that verifies the equation, Xi is an integer from [ -100,100] and XI ! = 0, any i∈{1,2,3,4}.
The question is not clear when a = B, whether the X1 and X2 can be regarded as one after the next is multiplied by 16 or according to the situation multiplied; the title person means not considering these
Idea: Directly enumerate the possible and value of two x1,x2, find the number of the opposite number in the other two, and use STL to find the number of repeating elements;
Time Complexity of O (N^2log (n^2)) n <= 100;
#include <iostream>#include<cstdio>#include<cstring>#include<string.h>#include<algorithm>#include<vector>#include<cmath>#include<stdlib.h>#include<time.h>#include<stack>#include<Set>#include<map>#include<queue>using namespacestd;#defineRep0 (I,L,R) for (int i = (l); i < (R); i++)#defineREP1 (I,L,R) for (int i = (l); I <= (r); i++)#defineRep_0 (i,r,l) for (int i = (r); i > (l); i--)#defineRep_1 (i,r,l) for (int i = (r); I >= (l); i--)#defineMS0 (a) memset (A,0,sizeof (a))#defineMS1 (a) memset (A,-1,sizeof (a))#defineMSi (a) memset (A,0x3f,sizeof (a))#defineINF 0x3f3f3f3f#defineLson L, M, RT << 1#defineRson m+1, R, RT << 1|1typedef __int64 Ll;template<typename t>voidRead1 (T &m) {T x=0, f=1;CharCh=GetChar (); while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} M= x*F;} Template<typename t>voidRead2 (T &a,t &b) {Read1 (a); Read1 (b);} Template<typename t>voidRead3 (T &a,t &b,t &c) {Read1 (a); Read1 (b); Read1 (c);} Template<typename t>void out(T a) {if(a>9) out(ATen); Putchar (A%Ten+'0');}inta[2][10010],top,f[ the];intSolveintNintMintID) {Top=0; REP1 (i,1, -){ intt = NF[i]; Rep1 (J,1, -) A[id][top+ +] = t + m*F[j]; } sort (A[id],a[id]+top);}intMain () {inta,b,c,d; REP1 (i,1, -) F[i] = i*i; while(SCANF ("%d%d%d%d", &a,&b,&c,&d) = =4){ if(A >0&& B >0&& C >0&& d >0) || (A <0&& B <0&& C <0&& D <0)) out(0); Else{ll ans=0; Solve (A, B,0); Solve (C,d,1); Rep0 (i,0, top) {ans+ = (Upper_bound (a[1],a[1]+top,-a[0][i])-Lower_bound (a[1],a[1]+top,-a[0][i])); } out(ans* -); } puts (""); } return 0;}View Code
HDU 1496 equations