题目链接:

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. tp 查询

  2. 云数据库 Redis 缓存 PHP session 变量

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

  3. ADO执行事务

    在工作中遇到,需要批量提交的.在sql2008以后有表变量定义,可以实现.但个人比较习惯用C#,就有下面代码,直接上代码... using (SqlConnection conn = new SqlC ...

  4. NET CORE Learning

    ASP.NET Core 基础教程https://www.cnblogs.com/lonelyxmas/tag/ASP.NET%20Core%20%E5%9F%BA%E7%A1%80%E6%95%99 ...

  5. perf命令

    @(Linux基础)[perf命令] perf命令 ---- 简介 Perf是内置于Linux内核源码树中的性能剖析(profiling)工具,它基于事件采样原理,以性能事件为基础,支持针对处理器相关 ...

  6. [转]使用jquery dataTable

    本文转自:http://blog.csdn.net/llhwin2010/article/details/8663753 jQuery 的插件 dataTables 是一个优秀的表格插件,提供了针对表 ...

  7. GridLayout(网格布局)

    常用属性: 排列对齐: ①设置组件的排列方式:  android:orientation=""     vertical(竖直,默认)或者horizontal(水平) ②设置组件的 ...

  8. Murano Weekly Meeting 2015.09.29

    Meeting time: 2015.September.29th 1:00~2:00 Chairperson:  Serg Melikyan, PTL from Mirantis Meeting s ...

  9. Hadoop2.X HA架构与部署

    HDFS-HA原理及配置 1.HDFS-HA架构原理介绍 hadoop2.x之后,Clouera提出了QJM/Qurom Journal Manager,这是一个基于Paxos算法实现的HDFS HA ...

  10. ubuntu14.04.2安装 YouCompleteme

    1 安装git ,按照这篇文章安装 http://www.cnblogs.com/or2-/p/4350252.html 2 安装编译需要的各种包 sudo apt-get install build ...