题目链接:

https://vjudge.net/problem/POJ-1840

题目大意:

给出一个5元3次方程,输入其5个系数,求它的解的个数

其中系数 ai∈[-50,50]  自变量xi∈[-50,0)∪(0,50]

注意:xi不为0

解题思路:

五重循环肯定TLE,所以选择三重循环+两重循环,然后排序,二分找相同的数字即可

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<map>
#include<set>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
ll cnt[];
const int maxn = 1e6 + ;
ll sum1[maxn];
ll sum2[maxn];
int main()
{
ll a, b, c, d, e;
cin >> a >> b >> c >> d >> e;
for(int i = -; i <= ; i++)cnt[i + ] = i * i * i;
int tot1 = , tot2 = ;
for(int i = -; i <= ; i++)
{
if(!i)continue;
for(int j = -; j <= ; j++)
{
if(!j)continue;
for(int k = -; k <= ; k++)
{
if(!k)continue;
sum1[tot1++] = a * cnt[i + ] + b * cnt[j + ] + c * cnt[k + ];
}
}
}
sort(sum1, sum1 + tot1); for(int i = -; i <= ; i++)
{
if(!i)continue;
for(int j = -; j <= ; j++)
{
if(!j)continue;
sum2[tot2++] = - d * cnt[i + ] - e * cnt[j + ];
}
}
sort(sum2, sum2 + tot2);
int ans = ;
for(int i = ; i < tot2; i++)
{
ans += (upper_bound(sum1, sum1 + tot1, sum2[i]) - sum1) - (lower_bound(sum1, sum1 + tot1, sum2[i]) - sum1);
}
cout<<ans<<endl;
return ;
}

POJ-1840 Eqs---二分的更多相关文章

  1. POJ 1840 Eqs 二分+map/hash

    Description Consider equations having the following form: a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0 The co ...

  2. poj 1840 Eqs 【解五元方程+分治+枚举打表+二分查找所有key 】

    Eqs Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 13955   Accepted: 6851 Description ...

  3. POJ 1840 Eqs 解方程式, 水题 难度:0

    题目 http://poj.org/problem?id=1840 题意 给 与数组a[5],其中-50<=a[i]<=50,0<=i<5,求有多少组不同的x[5],使得a[0 ...

  4. poj 1840 Eqs (hash)

    题目:http://poj.org/problem?id=1840 题解:http://blog.csdn.net/lyy289065406/article/details/6647387 小优姐讲的 ...

  5. POJ 1840 Eqs

    Eqs Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 15010   Accepted: 7366 Description ...

  6. POJ 1840 Eqs(hash)

    题意  输入a1,a2,a3,a4,a5  求有多少种不同的x1,x2,x3,x4,x5序列使得等式成立   a,x取值在-50到50之间 直接暴力的话肯定会超时的   100的五次方  10e了都 ...

  7. POJ 1840 Eqs 暴力

      Description Consider equations having the following form: a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0 The ...

  8. POJ 1840 Eqs(乱搞)题解

    思路:这题好像以前有类似的讲过,我们把等式移一下,变成 -(a1*x1^3 + a2*x2^3)== a3*x3^3 + a4*x4^3 + a5*x5^3,那么我们只要先预处理求出左边的答案,然后再 ...

  9. poj 2318 叉积+二分

    TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 13262   Accepted: 6412 Description ...

  10. poj 2049(二分+spfa判负环)

    poj 2049(二分+spfa判负环) 给你一堆字符串,若字符串x的后两个字符和y的前两个字符相连,那么x可向y连边.问字符串环的平均最小值是多少.1 ≤ n ≤ 100000,有多组数据. 首先根 ...

随机推荐

  1. 用HTMLParser解析html时报错:No module named 'htmlentitydefs'

    python3.6用HTMLParser解析html时报错 No module named 'htmlentitydefs'或No module named 'markupbase' 先上代码 fro ...

  2. java——巨简陋文本编辑器

    String :equals()方法是进行内容比较,而不是引用比较. “==”比较两个变量本身的值,即两个对象在内存中的首地址. Scanner :用Scanner实现字符串的输入有两种方法,一种是n ...

  3. Spring Boot 实现ErrorController接口处理404、500等错误页面

    在项目中我们遇到404找不到的错误.或者500服务器错误都需要配置相应的页面给用户一个友好的提示,而在Spring Boot中我们需要如何设置. 我们需要实现ErrorController接口,重写h ...

  4. MATLAB基本概念和变量

    基本概念 1.x=int8(129)=>x=127     (带符号8位整数,最大值为127) x=uint8(129)=>x=129  (无符号型,最大值为255) 2.class函数得 ...

  5. 二叉查找树的C语言实现(二)

    接着上次的话题.这次我们要讨论,二叉查找树的中序遍历和后序遍历(递归和非递归),另外还有先序遍历(非递归) 1.中序遍历(递归) static void __in_order(struct bnode ...

  6. RMAN参数详解

    在Oracle 10g中的配置情况使用RMAN>show all;可以显示出RMAN 配置参数为: CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # d ...

  7. HDU 4612——Warm up——————【边双连通分量、树的直径】

    Warm up Time Limit:5000MS     Memory Limit:65535KB     64bit IO Format:%I64d & %I64u Submit Stat ...

  8. 同源策略引发对跨域jsonp跨域的理解

    一,同源策略其实网络的安全基石,既:http://www.baidu.com:80协议(http或者HTTPS或者ws或者wss).域名(www.baidu.com).端口(默认80,可以不写 htt ...

  9. 新浪微博OAuth2授权错误 error:redirect_uri_mismatch

    最近想在app进行新浪微博认证,结果发现总是报error:redirect_uri_mismatch错误. 网上搜了解决方法. 进入 http://open.weibo.com/apps/app_ke ...

  10. HTML标签_2