Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
这题用不着哈希吧!二分+暴力,直接开个100W数组记录,加上qsort。var f:array[0..1000000,0..1]of longint; a,b,c,d,e,i,j,k,n,ans,temp,l,r,mid:longint; procedure qsort(l,r:longint); var i,j,x:longint; y:array[0..1]of longint; begin i:=l;j:=r; x:=f[(l+r)>>1,0]; repeat while f[i,0]<x do inc(i); while x<f[j,0] do dec(j); if not(i>j) then begin y:=f[i]; f[i]:=f[j]; f[j]:=y; inc(i); dec(j); end; until i>j; if l<j then qsort(l,j); if i<r then qsort(i,r); end; function pow(x:longint):longint; begin exit(x*x*x); end; begin readln(a,b,c,d,e); for i:=-50 to 50 do for j:=-50 to 50 do for k:=-50 to 50 do if (i<>0)and(j<>0)and(k<>0) then begin inc(n); f[n,0]:=a*pow(i)+b*pow(j)+c*pow(k); f[n,1]:=1; end; qsort(1,n); i:=0; while i<n do begin inc(i); k:=1; for j:=i+1 to n do if f[i,0]=f[j,0] then inc(k) else break; for j:=i to i+k-1 do f[j,1]:=k; inc(i,k-1); end; for i:=-50 to 50 do for j:=-50 to 50 do if (i<>0)and(j<>0) then begin temp:=-pow(i)*d-pow(j)*e; l:=1; r:=n; while l<r do begin mid:=(l+r)>>1; if f[mid,0]<temp then l:=mid+1 else r:=mid; end; if f[l,0]=temp then inc(ans,f[l,1]); end; writeln(ans); end. Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator