| ||||||||||
| 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 | |||||||||
大牛帮我看看我的程序错在什么地方啊!我用的是二分!
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
const int M=1000100;
const int N=10010;
__int64 A[M];
__int64 B[M];
__int64 a[N];
__int64 b[N];
__int64 c[N];
__int64 d[N];
__int64 e[N];
int f[105];
int main()
{
int low,high,mid,i,j,k,len1,len2,m;
int a1,a2,a3,a4,a5;
__int64 ans;
m=0;
for(i=-50;i<=50;i++)
if(i!=0)
f[++m]=i*i*i;
f[0]=m;
while(scanf("%d%d%d%d%d",&a1,&a2,&a3,&a4,&a5)==5)
{
for(i=1;i<=f[0];i++)
{
a[i]=a1*f[i];
b[i]=a2*f[i];
c[i]=a3*f[i];
d[i]=a4*f[i];
e[i]=a5*f[i];
}
len1=0;
for(i=1;i<=f[0];i++)
for(j=1;j<=f[0];j++)
for(k=1;k<=f[0];k++)
A[++len1]=a[i]+b[j]+c[k];
A[0]=len1;
len2=0;
for(i=1;i<=f[0];i++)
for(j=1;j<=f[0];j++)
B[++len2]=d[i]+e[j];
B[0]=len2;
sort(B+1,B+len2+1);
ans=0;
for(i=1;i<=A[0];i++)
{
low=1;
high=B[0];
while(low<=high)
{
mid=(low+high)/2;
if(A[i]+B[mid]==0)
{
ans++;
//printf("ans==%d\n",ans);
break;
}
else if(A[i]+B[mid]>0)
high=mid-1;
else
low=mid+1;
}
}
printf("%I64d\n",ans);
}
return 0;
}
/*
37 29 41 43 47
654
*/
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator