Eqs 折半枚举+二分查找 大水题

                        Eqs

题目抽象:a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0 (*),给出a1,a2,a3,a4,a5.    ai属于[-50,50].

求有多少序列   x1,x2,x3,x4,x5 ,xi属于 [-50,50]-{0}.

思路:折半枚举+二分查找

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cmath>
 5 #include <algorithm>
 6 #include <map>
 7 using namespace std;
 8 typedef long long LL;
 9 const int MS=50;
10 const int SIZE=10000;
11 
12 int hash[SIZE];
13 int cnt;
14 
15 int main()
16 {
17     int a1,a2,a3,a4,a5;
18     while(scanf("%d%d%d%d%d",&a1,&a2,&a3,&a4,&a5)!=EOF)
19     {
20         cnt=0;
21         for(int i=-MS;i<=MS;i++)
22             for(int j=-MS;j<=MS;j++)
23         {
24             if(i==0||j==0)
25                 continue;
26             int t=a1*i*i*i+a2*j*j*j;
27             hash[cnt++]=t;
28         }
29         sort(hash,hash+cnt);
30         int ans=0;
31         for(int i=-MS;i<=MS;i++)
32             for(int j=-MS;j<=MS;j++)
33                 for(int k=-MS;k<=MS;k++)
34         {
35             if(i==0||j==0||k==0)
36                 continue;
37             int t=a3*i*i*i+a4*j*j*j+a5*k*k*k;
38             ans+=upper_bound(hash,hash+cnt,-t)-lower_bound(hash,hash+cnt,-t);
39         }
40         printf("%d\n",ans);
41     }
42     return 0;
43 }

 

转载于:https://www.cnblogs.com/hutaishi/p/4493021.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值