题目链接:

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 字符串的特性

    #######str字符串#####str字符判断大小写  url1 = 'http://www.cctv.com'  url2 = 'file:///mnt'  print url1.startsw ...

  2. sonar 测试覆盖率

    <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</a ...

  3. UntraEdit 语法高亮 (MSSQL)

    http://www.ultraedit.com/downloads/extras/wordfiles.html 这里有ue 支持的语言的uew文件. 需要把下载的语法文件放到: %APPDATA%\ ...

  4. Why Nexiq 125032 USB Link Truck diagnostic tool is so helpful ?

    As for as I am concerned , Heavy Duty Diagnostic Nexiq 125032 USB is a helpful tool , which has exce ...

  5. 如何利用fastjson将JSON格式的字符串转换为Map,再返回至前端成为js对象

    //注意,这里的jsonStr是json格式的字符串,里面如果遇到双引号嵌套双引号的,一般是嵌套的双引号经过转义 //    \",假如有这样的一个场景,这些字符串里面有需要的css样式的j ...

  6. 3d Max 2017安装失败怎样卸载3dsmax?错误提示某些产品无法安装

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

  7. Unity 平台宏定义

    官方文档: https://docs.unity3d.com/Manual/PlatformDependentCompilation.html

  8. (转)TCP连接的11种状态变迁

    自:http://blog.csdn.net/engrossment/article/details/8104482 http://blog.csdn.net/xiaofei0859/article/ ...

  9. Get和Post区别,EncType提交数据的格式详解——转自他人博客的

    1. get是从服务器上获取数据,post是向服务器传送数据. 2. get是把参数数据队列加到提交表单的ACTION属性所指的URL中,值和表单内各个字段一一对应,在URL中可以看到.post是通过 ...

  10. Java学习第十六天

    1:List的子类(掌握) (1)List的子类特点 ArrayList: 底层数据结构是数组,查询快,增删慢 线程不安全,效率高 Vector: 底层数据结构是数组,查询快,增删慢 线程安全,效率低 ...