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 |
O(log2(10)*10^6)..........0ms1.由于b<c<d,故b^3<c^3<d^3,所以 3b^3<b^3+c^3+d^3=a^3,即b<=a/1.44224957 2.设cube[i]=i^3,cube[i]单调,故只需枚举a,b,c并在二分查找cube[a]-cube[b]-cube[c]是否存在 3.b^3<c^3<d^3,所以cube[a]-cube[b]-cube[c]>cube[b]且>cube[c] 4.二分查找容易写错....... #include <stdio.h> //Binary Search used,the time complexity will be O(10^6*log2(10)) int cube[101],n,i,j,limit,l,t; int find(int num) { int left=1,right=l,mid; while (left<right) { mid=(left+right)>>1; if (cube[mid]==num) return mid; else if (cube[mid-1]==num) return mid-1; else if (cube[mid]<num) left=mid+1; else right=mid-1; } return 0; } int main() { scanf("%d",&n); cube[1]=1; for (i=2;i<=n;i++) cube[i]=cube[i-1]+3*i*i-3*i+1; for (l=6;l<=n;l++) { limit=l/1.44224957+1; for (i=2;i<=limit;i++) for (j=i;j<=n;j++) { t=cube[l]-cube[i]-cube[j]; if (t<cube[i] || t<cube[j]) break; t=find(t); if (t>0) printf("Cube = %d, Triple = (%d,%d,%d)\n",l,i,j,t); } } scanf("%d",&i); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator