题目链接:

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. 云数据库 Redis 缓存 PHP session 变量

    1.安装 phpredis 扩展. wget https://github.com/nicolasff/phpredis/archive/master.zip unzip master.zip cd ...

  2. MYSQL生成两个日期之间的所有日期数据

    set @i = -1; set @sql = repeat(" select 1 union all",-datediff('2021-01-01','2030-12-31')+ ...

  3. my.宠物升级79级

    1.蚌仙子 74级半不到的时候,吃  月华露(500000经验的那种)  吃3个 正好 79级半 我记得 之前 是升满75级 再吃月华露 到79级的时候 经验溢出了.不突破还好,突破的话 宠物就升级了 ...

  4. c++ 封装线程库 0

    1.互斥锁简介 互斥锁主要用于互斥,互斥是一种竞争关系,用来保护临界资源一次只被一个线程访问. POSIX Pthread提供下面函数用来操作互斥锁. int pthread_mutex_init(p ...

  5. 可输入的 Combox(DropDownList)

    aspx页面中需要可以输入的combox,在网上找了一个js的插件,效果图如下:

  6. python—datetime time 模板学习

    写在前面:本人在学习此内容是通过 https://www.cnblogs.com/pycode/p/date.html 文章学习! 时间模块——time python 中时间表示方法有:时间戳_:格式 ...

  7. sqoop导出数据

    export是HDFS里的文件导出到RDBMS的工具,不能从hive.hbase导出数据,且HDFS文件只能是文本格式.如果要把hive表数据导出到RDBMS,可以先把hive表通过查询写入到一个临时 ...

  8. Android Studio CMake 生成多个so

    生成多个so案例 这里stringFromJNI和stringFromJNI11分别是调用one-lib和two-lib两个so package com.test.ndkmoreso; import ...

  9. java替换word表格2007

    package demo;import java.io.FileOutputStream;import java.util.HashMap;import java.util.Iterator;impo ...

  10. nginx 访问路径配置

    比如: http://127.0.0.1/ 对应的物理路径 c:/a/b/c 比如:http://127.0.0.1/eec 访问的地址对应的物理路径: d:/a/b/c #user nobody; ...