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. PHP 判断手机号归属地 和 运营商的免费接口

    在项目开发的时候,需要去查询又一批手机号或者固话的具体信息(归属地 运营商) 就需要写一个脚本,来批量请求接口来得到我们想要的数据 学习源头:https://blog.csdn.net/shaerdo ...

  2. 使用妹子UI开发的体验分享

    前阵子看到一个类似bootstrap的前端UI框架,好奇心驱使下,去琢磨了一些,最终决定网站改版用这个UI试试效果: 首页+头部: 投稿页: 现成拷贝过来的评论列表: 总结: 上手难度: (熟悉boo ...

  3. java代码----equals和==区别

    总结: ==的意义在于比较的是整型 package com.aa; // public class Bd { public static void main(String[] args) { Inte ...

  4. 分表分库之二:唯一ID的生成方法

    一.为什么要全局唯一? 我们在对数据库集群作扩容时,为了保证负载的平衡,需要在不同的Shard之间进行数据的移动, 如果主键不唯一,我们就没办法这样随意的移动数据.起初,我们考虑采用组合主键来解决这个 ...

  5. [Kingdom Rush]团队分享:如何做塔防手游

    转自:http://www.gamelook.com.cn/2015/03/207324 GameLook报道/2014年11月,乌拉圭开发商Ironhide Studios发布的<Kingdo ...

  6. MFC学习(四) 消息机制

    1 消息机制的要点: 消息队列:先进先出 消息循环:通过循环while,不断的从消息队列中取得队首消息,并分发消息. 消息处理:根据不同的消息类型做不同的处理 事件:事件响应函数 2 消息机制 _tW ...

  7. linux lcd设备驱动剖析三

    上一节文章中详细地剖析了probe函数,但是从始至终都没有看到打开读写文件接口的操作函数,只看到了下面这个操作结构体 [cpp] view plain? static struct fb_ops s3 ...

  8. js中的webworker

    js中的webworker webworker的作用类似于java的多线程 以独立文件的形式运行webworker index.html <!DOCTYPE html> <html ...

  9. RAD 10 蓝牙

    http://docwiki.embarcadero.com/Libraries/Seattle/en/System.Bluetooth.TBluetoothLEManager.StartDiscov ...

  10. linux中memset的正确用法

    linux中memset的正确用法 [起因]希望对各种类型的数组进行初始化,避免野值 [函数头文件] 提示:在linux中可以在terminal中输入 "man memset"进行 ...