/*The problem of 10^8 violence can be answered but slow ..... There is a small bug that the person card int but did not pay attention to short with short can not hash directly to engage
49428K 313MS */#include<iostream>#include<cstdio>#include<cstring>#defineBase 12500000using namespacestd;intA1,a2,a3,a4,a5,x1,x2,x3,x4,x5,ans; Shortf[12500000*2+ -];intMain () {scanf ("%d%d%d%d%d",&a1,&a2,&a3,&a4,&a5); for(x1=- -; x1<= -; x1++)if(x1) for(x2=- -; x2<= -; x2++)if(x2) {ints=a1*x1*x1*x1+a2*x2*x2*x2; S+=Base; f[s]++; } for(x3=- -; x3<= -; x3++)if(x3) for(x4=- -; x4<= -; x4++)if(x4) for(x5=- -; x5<= -; x5++)if(X5) {ints=a3*x3*x3*x3+a4*x4*x4*x4+a5*x5*x5*X5; if(s>12500000|| s<-12500000)Continue; S=-s;s+=Base; ans+=F[s]; } printf ("%d\n", ans); return 0;}
/*Suddenly feel that they have not learned the same hash .... The problem is that two parts of the answer need to be saved, but the number is very large as the subscript can not be used to do it. For each value s to calculate its Hsah value to control the value in a certain range of course, such a large probability of repetition does not matter we use the side table next to the hash value as the number of points And then point to S to find a number of s that have several corresponding time to the value of the hash value of s to traverse the statistics there are several of the same as S
12412K 891MS */#include<iostream>#include<cstdio>#include<cstring>#defineMAXN 1000010#defineMoD 1000007using namespacestd;intA1,a2,a3,a4,a5,x1,x2,x3,x4,x5,ans;intHead[maxn],num;structnode{intV,pre;} E[MAXN];voidADD (intTo ) { intX;x=to>0? to:-to ; int from= (x%mod+x/mod)%MoD; Num++;e[num].v=to ; E[num].pre=head[ from]; head[ from]=num;}intFindintTo ) { intret=0;intX;x=to>0? to:-to ; int from= (x%mod+x/mod)%MoD; for(inti=head[ from];i;i=e[i].pre)if(e[i].v==to) ret++; returnret;}intMain () {scanf ("%d%d%d%d%d",&a1,&a2,&a3,&a4,&a5); for(x1=- -; x1<= -; x1++)if(x1) for(x2=- -; x2<= -; x2++)if(x2) for(x3=- -; x3<= -; x3++)if(x3) {ints=a1*x1*x1*x1+a2*x2*x2*x2+a3*x3*x3*X3; ADD (s); } for(x4=- -; x4<= -; x4++)if(x4) for(x5=- -; x5<= -; x5++)if(X5) {ints=a4*x4*x4*x4+a5*x5*x5*X5; Ans+=find (s); } printf ("%d\n", ans); return 0;}
/*Finally, I put my deskmate in the second point find 704K 1907MS */#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<map>#defineMAXN 10010using namespacestd;inta[6],x[6],f[ $],TOT,ANS,P[MAXN];intMain () {inti,j,k; for(i=1; i<=5; i++) scanf ("%d",&A[i]); for(x[1]=- -; x[1]<= -; x[1]++) { if(x[1]==0)Continue; for(x[2]=- -; x[2]<= -; x[2]++) { if(x[2]==0)Continue; intsum=a[1]*x[1]*x[1]*x[1]+a[2]*x[2]*x[2]*x[2]; p[++tot]=sum; }} sort (P+1, p+tot+1); for(x[3]=- -; x[3]<= -; x[3]++) { if(x[3]==0)Continue; for(x[4]=- -; x[4]<= -; x[4]++) { if(x[4]==0)Continue; for(x[5]=- -; x[5]<= -; x[5]++) { if(x[5]==0)Continue; intsum=a[3]*x[3]*x[3]*x[3]+a[4]*x[4]*x[4]*x[4]+a[5]*x[5]*x[5]*x[5]; Ans+ = (Upper_bound (p+1, p+tot+1,-sum)-P)-(Lower_bound (p+1, p+tot+1,-sum)-p); }}} printf ("%d\n", ans); return 0;}
POJ 1840 Eqs (Hash)