Eqs(枚举+ hash)
http://poj.org/problem?id=1840
题意:给出系数a1,a2,a3,a4,a5,求满足方程的解有多少组。
思路:有a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0 可得 -(a1x13+ a2x23) = a3x33+ a4x43+ a5x53;
先枚举x1,x2,用hash[]记录 sum出现的次数,然后枚举后三个点,若左边出现的sum在右边可以找到,那么hash[sum]即为解的个数。
#include <cstdio>
#include <string.h>
#include <iostream>
#define N 25000000
using namespace std;
short hash[N+]; int main()
{
int a1,a2,a3,a4,a5;
while(cin>>a1>>a2>>a3>>a4>>a5)
{
int x1,x2,x3,x4,x5;
int ans = ;
memset(hash,,sizeof(hash));
for (x1 = -; x1 <= ; x1 ++)
{
if(!x1) continue;
for (x2 = -; x2 <= ; x2 ++)
{
if (!x2) continue;
int sum =(a1*x1*x1*x1+a2*x2*x2*x2)*(-);
if (sum < )
sum += N;
hash[sum]++; }
}
for (x3 = -; x3 <= ; x3 ++)
{
if(!x3) continue;
for (x4 = -; x4 <= ; x4 ++)
{
if (!x4) continue;
for (x5 = -; x5 <= ; x5 ++)
{
if (!x5) continue;
int sum = a3*x3*x3*x3+a4*x4*x4*x4+a5*x5*x5*x5;
if (sum < )
sum += N;
if (hash[sum])
ans += hash[sum];
}
}
}
cout<<ans<<endl;
}
return ;
}
Eqs(枚举+ hash)的更多相关文章
- POJ1840: Eqs(hash问题)
一道典型的hash问题: 已知a1,a2,a3,a4,a5,求有多少种不同的<x1,x2,x3,x4,x5>组合满足等式: a1*x1^3 + a2*x2^3 + a3*x3^3 + a4 ...
- Codeforces1056E.Check Transcription(枚举+Hash)
题目链接:传送门 题目: E. Check Transcription time limit per test seconds memory limit per test megabytes inpu ...
- 折半枚举+Hash(HDU1496升级版)
题目链接:N - 方程的解 给定一个四元二次方程: Ax1^2+Bx2^2+Cx3^2+Dx4^2=0 试求−1000≤x1,x2,x3,x4≤1000非零整数解的个数. −10000≤A,B,C,D ...
- poj 1840 Eqs (hash)
题目:http://poj.org/problem?id=1840 题解:http://blog.csdn.net/lyy289065406/article/details/6647387 小优姐讲的 ...
- [JSOI2009]电子字典 hash
题面:洛谷 题解: 做法....非常暴力. 因为要求的编辑距离最多只有1,所以我们直接枚举对那个位置(字符)进行操作,进行什么样的操作,加入/修改/删除哪个字符,然后暴力枚举hash判断即可, #in ...
- BZOJ3198 [Sdoi2013]spring 哈希 容斥原理
欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ3198 题意概括 有n(1<=n<=100000)组数据,每组数据6个数. 现在问有几对 ...
- SDUT OJ 2607
/*http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2607*/ 题目大意:给出一个字符串,求出里 ...
- Surprising Strings
Surprising Strings Time Limit: 1000MS Memory Limit: 65536K Total Submissions: Accepted: Description ...
- 普转提Day1
T1 给定一个长度为N的序列,去掉其中连续的一部分使得剩下的部分没有重复元素. 很显然可以发现去掉的一部分只有三种情况:开头.中间.最后. 那么我们只需要枚举Hash就可以了.复杂度O(N^2). 不 ...
随机推荐
- block要用copy修饰,还是用strong
栈区与堆区 block本身是像对象一样可以retain,和release.但是,block在创建的时候,它的内存是分配在栈(stack)上,而不是在堆(heap)上.他本身的作于域是属于创建时候的作用 ...
- PHP 之ip查询接口
/** * @param $ip 待查询的ip * @return mixed */ function getIpAddressInfo($ip) { $ipurl = 'http://api.ip1 ...
- 文件上传原理--FileReader
单个文件:<div> <input value="上传" type="file" id="photos_upload"&g ...
- 报错:command not found
linux中如果是最小化安装的系统,执行命令的时候很多会出现没找到命令 [root@localhost ~]# mtr -bash: mtr: command not found [root@loca ...
- 图像处理中创建CDib类时无法选择基类类型时怎么办
图像处理中创建CDib类时无法选择基类类型时怎么办? 类的类型选择Generic Class 在下面的篮筐里输入CObject就行了
- spine骨骼动画组件使用详解
1. spine骨骼动画工具 骨骼动画: 把动画打散, 通过工具,调骨骼的运动等来形成动画spine是一个非常流行的2D骨骼动画制作工具spine 动画美术人员导出3个文件: (1) .png文 ...
- Going Home HDU - 1533(最大费用最小流)
On a grid map there are n little men and n houses. In each unit time, every little man can move one ...
- 3.git高级篇总结
阅读 Git 原理详解及实用指南 记录 高级 1:不喜欢merge的分叉,用rebase吧 介绍的是 rebase 指令,它可以改变 commit 序列的基础点.它的使用方式很简单: git reba ...
- 学习记录--如何将exec执行结果放入变量中?
declare @num int, ) set @sqls='select @a=count(*) from tb ' exec sp_executesql @sqls,N'@a int output ...
- BUPT2017 springtraining(16) #6 ——图论
题目链接 A.容易发现最后字符的对应都是一对一的 或者说我们没办法出现最后多对一或者一对多的情况 所以只要算出 ‘a’ - 'z' 每个字符最后对应的字符即可 #include <cstdio& ...