题目链接:

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. python 文件与异常

    ####文件### r: -只能读 不能写 -读取文件不存在,是会报错 r+: - 可以执行读写操作; - 文件不存在, 报错: w: -只能写,不能读 -会清空文件内容 -文件不存在,会新建文件 w ...

  2. kafkaconsumer SimpleExample

    package kafka.simple; import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Colle ...

  3. gitlab 的安装、汉化、卸载

    新机 dell服务器 2核4G 官网: https://about.gitlab.com/install/ 1.本次安装选择版本v10.8.4 wget https://mirrors.tuna.ts ...

  4. 转 RMAN-20005: target database name is ambiguous

    发生的这个错误的由于: 在RMAN CATALOG中,register了一个name叫test的数据库,后来这个库被我搞坏了.就重建了一个test的数据库,名称没有更改,又重新register到RMA ...

  5. CAD安装失败怎样卸载CAD 2015?错误提示某些产品无法安装

    AUTODESK系列软件着实令人头疼,安装失败之后不能完全卸载!!!(比如maya,cad,3dsmax等).有时手动删除注册表重装之后还是会出现各种问题,每个版本的C++Runtime和.NET f ...

  6. axios处理http请求

    axios中文文档 https://github.com/mzabriskie/axios#using-applicationx-www-form-urlencoded-format  axios文档 ...

  7. 《深入浅出Node.js》学习笔记(一)

    看了朴灵前辈的node.js系列文章,很开阔视野,虽然能力有限还是有很多不懂,但是还是希望能写下笔记,初步对node.js有点了解. 一.概念 Node.js不是JS应用.而是JS运行平台 Node. ...

  8. linux 统计TCP 连接各状态总数

    netstat  -n|awk '/^tcp/ {++s[$NF]} END {for(k in s) print k, s[k]}' 以前经常只是从笔记中复制下, 这次打算 研究下 awk 语法 . ...

  9. script脚本中写不写$(document).ready(function() {});的区别

    $(document).ready() 里的代码是在页面内容都加载完才执行的,如果把代码直接写到script标签里,当页面加载完这个script标签就会执行里边的代码了,此时如果你标签里执行的代码调用 ...

  10. 获得数据库image图片二进制

    /// <summary>        /// 获得图片二进制        /// </summary>        /// <param name="u ...