| ||||||||||
| 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 <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <map>
using namespace std;
typedef long long LL;
const int MS=50;
const int SIZE=10000;
int hash[SIZE];
int cnt;
int main()
{
int a1,a2,a3,a4,a5;
while(scanf("%d%d%d%d%d",&a1,&a2,&a3,&a4,&a5)!=EOF)
{
cnt=0;
for(int i=-MS;i<=MS;i++)
for(int j=-MS;j<=MS;j++)
{
if(i==0||j==0)
continue;
int t=a1*i*i*i+a2*j*j*j;
hash[cnt++]=t;
}
sort(hash,hash+cnt);
int ans=0;
for(int i=-MS;i<=MS;i++)
for(int j=-MS;j<=MS;j++)
for(int k=-MS;k<=MS;k++)
{
if(i==0||j==0||k==0)
continue;
int t=a3*i*i*i+a4*j*j*j+a5*k*k*k;
ans+=upper_bound(hash,hash+cnt,-t)-lower_bound(hash,hash+cnt,-t);
}
printf("%d\n",ans);
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator