Description

Consider equations having the following form: 
a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0 
The coefficients are given integers from the interval [-50,50]. 
It is consider a solution a system (x1, x2, x3, x4, x5) that verifies the equation, xi∈[-50,50], xi != 0, any i∈{1,2,3,4,5}. 

Determine how many solutions satisfy the given equation. 

Input

The only line of input contains the 5 coefficients a1, a2, a3, a4, a5, separated by blanks.

Output

The output will contain on the first line the number of the solutions for the given equation.

Sample Input

37 29 41 43 47

Sample Output

654
题意:求a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0 在x∈[-50,50]且x!=0的解的个数
x1=a且x2=b与x1=b且x2=a算两个解
题解:因为a1,a2,a3,a4,a5是固定的,所以只需要枚举x1,x2,x3,x4,x5即可
复杂度为O(n^5)
等等!O(n^5)?!
这是要t的节奏啊
该怎么办呢?
改下公式吧~
a3x33+ a4x43+ a5x53=-a1x13 -a2x23
这样先枚举右边的解数,再枚举x3,x4,x5,看看满不满足右边即可
这种折半枚举的思路很好,至于如何检验满不满足,本来是准备用map的,结果t了
于是只好hash了……
最好打的hash704ms,好像也不坏
至于poj的abs……emmm也是醉了
代码如下:
#pragma GCC optimize(2)
#include<map>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x3f3f3f3f
using namespace std; vector<long long> g[];
int a1,a2,a3,a4,a5,ans; int main()
{
scanf("%d%d%d%d%d",&a1,&a2,&a3,&a4,&a5);
for(int i=-; i<=; i++)
{
if(!i)
{
continue;
}
for(int j=-; j<=; j++)
{
if(!j)
{
continue;
}
long long x=a1*(i*i*i)+a2*(j*j*j);
int key=x<?(-x)%:x%;
g[key].push_back(x);
}
}
for(int i=-; i<=; i++)
{
if(!i)
{
continue;
}
for(int j=-; j<=; j++)
{
if(!j)
{
continue;
}
for(int k=-; k<=; k++)
{
if(!k)
{
continue;
}
long long y=a3*(i*i*i)+a4*(j*j*j)+a5*(k*k*k);
int key=y<?(-y)%:y%;
for(int w=;w<g[key].size();w++)
{
if(g[key][w]==-y)
{
ans++;
}
}
}
}
}
printf("%d\n",ans);
}



poj1840 Eqs(hash+折半枚举)的更多相关文章

  1. poj2002 Squares(hash+折半枚举)

    Description A square is a 4-sided polygon whose sides have equal length and adjacent sides form 90-d ...

  2. 折半枚举+Hash(HDU1496升级版)

    题目链接:N - 方程的解 给定一个四元二次方程: Ax1^2+Bx2^2+Cx3^2+Dx4^2=0 试求−1000≤x1,x2,x3,x4≤1000非零整数解的个数. −10000≤A,B,C,D ...

  3. Load Balancing 折半枚举大法好啊

    Load Balancing 给出每个学生的学分.   将学生按学分分成四组,使得sigma (sumi-n/4)最小.         算法:   折半枚举 #include <iostrea ...

  4. CSU OJ PID=1514: Packs 超大背包问题,折半枚举+二分查找。

    1514: Packs Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 61  Solved: 4[Submit][Status][Web Board] ...

  5. NYOJ 1091 超大01背包(折半枚举)

    这道题乍一看是普通的01背包,最最基础的,但是仔细一看数据,发现普通的根本没法做,仔细观察数组发现n比较小,利用这个特点将它划分为前半部分和后半部分这样就好了,当时在网上找题解,找不到,后来在挑战程序 ...

  6. Codeforces 888E - Maximum Subsequence(折半枚举(meet-in-the-middle))

    888E - Maximum Subsequence 思路:折半枚举. 代码: #include<bits/stdc++.h> using namespace std; #define l ...

  7. Codeforces 912 E.Prime Gift (折半枚举、二分)

    题目链接:Prime Gift 题意: 给出了n(1<=n<=16)个互不相同的质数pi(2<=pi<=100),现在要求第k大个约数全在所给质数集的数.(保证这个数不超过1e ...

  8. poj_3977 折半枚举

    题目大意 给定N(N<=35)个数字,每个数字都<= 2^15. 其中一个或多个数字加和可以得到s,求出s的绝对值的最小值,并给出当s取绝对值最小值时,需要加和的数字的个数. 题目分析 需 ...

  9. POJ 3977 Subset(折半枚举+二分)

    SubsetTime Limit: 30000MS        Memory Limit: 65536KTotal Submissions: 6754        Accepted: 1277 D ...

随机推荐

  1. 有关Botton的用法(二)

    关于设置listener监听onClicked事件的步骤分析 Steps: 1.tell android you are interested in listening to a button cli ...

  2. CString 中的SpanIncluding 和SpanExcluding 用法

    SpanIncluding 简单的理解就是提取包含在指定串中的一个子串 MSDN上的备注说:从左边的第一个字符开始查找与给定串相等的字符,如果没有则返回空的串,反之,继续查找,到结束. 例子方便理解 ...

  3. python3 安装 past 包

    python3 安装 past 包 $ pip install future 错误现象 缺乏包的引用 from past.types import unicode 参考链接 https://pypi. ...

  4. 【转】Jmeter的正则表达式未正确提取数据

    在进行脚本调试时,在Apply-Money-Page中需要Save-base中header的id参数,采用正则表达式提取器获取 使用正则表达式提取器,结果无法获取到需要的参数 最后定位是因为[?]是一 ...

  5. java中length的用法

    总结:length是属性...有很多种,不仅仅是指长度 package com.c2; import java.io.BufferedReader; import java.io.IOExceptio ...

  6. js 格式化相关的时间

    javascript Date format(js日期格式化) 方法一: // 对Date的扩展,将 Date 转化为指定格式的String // 月(M).日(d).小时(h).分(m).秒(s). ...

  7. 根文件系统的构建与分析(四)之瑞士军刀busybox生成系统基本命令

    根文件系统的构建与分析(四) 转载请注明 http://blog.csdn.net/jianchi88   Author:Lotte   邮箱:baihaowen08@126.com ls /bin, ...

  8. springboot成神之——Basic Auth应用

    本文介绍Basic Auth在spring中的应用 目录结构 依赖 入口DemoApplication 验证Authenication 配置WebSecurityConfig 控制器TestContr ...

  9. Windows下搭建PHP开发环境-WEB服务器

    PHP集成开发环境有很多,如XAMPP.AppServ......只要一键安装就把PHP环境给搭建好了.但这种安装方式不够灵活,软件的自由组合不方便,同时也不利于学习.所以我还是喜欢手工搭建PHP开发 ...

  10. Python Twisted系列教程5:由Twisted支持的诗歌客户端

    作者:dave@http://krondo.com/twistier-poetry/  译者:杨晓伟(采用意译) 你可以从这里从头开始阅读这个系列 抽象地构建客户端 在第四部分中,我们构建了第一个使用 ...