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). 不 ...
随机推荐
- PHP 之websocket实现聊天室功能
一.功能界面 具体的详细代码:https://github.com/yangsphp/websocket-master/tree/master 二.具体代码实现 1.前端代码如下 <!DOCTY ...
- __declspec(dllexport)
__declspec(dllexport) (2010-06-17 10:04:28) 转载▼ 标签: __declspec dllexport 导出 it 分类: C 先看代码:以下是在dev-c+ ...
- 原生js实现瀑布流效果
参考此篇:https://segmentfault.com/a/1190000012621936 以下为个人测试中: css: .masonry{ width:100%; } .item{ posit ...
- CAD绘制一个角度标注(com接口VB语言)
主要用到函数说明: _DMxDrawX::DrawDimAngular 绘制一个角度标注.详细说明如下: 参数 说明 DOUBLE dAngleVertexX 角度标注的顶点的X值 DOUBLE dA ...
- [luogu2148 SDOI2009] E&D (博弈论)
传送门 Solution 我们知道当SG不为0则先手必胜,然后就可以打表了 ̄▽ ̄ Code //By Menteur_Hxy #include <cmath> #include <c ...
- CSS练习:仿小米官网
代码: <!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="UT ...
- 3.git高级篇总结
阅读 Git 原理详解及实用指南 记录 高级 1:不喜欢merge的分叉,用rebase吧 介绍的是 rebase 指令,它可以改变 commit 序列的基础点.它的使用方式很简单: git reba ...
- Mysql学习总结(40)——MySql之Select用法汇总
一.条件筛选 1.数字筛选:sql = "Select * from [sheet1$] Where 销售单价 > 100" 2.字符条件:sql = "Selec ...
- OpenCV 基于超像素分割的图像区域选取方法及源码
本系列文章由 @yhl_leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/51386993 工程源码GitHub: ...
- POJ——T 1160 Post Office
http://poj.org/problem?id=1160 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 20218 ...