poj1840--Eqs
来源:互联网 发布:js获取url中的参数 编辑:程序博客网 时间:2024/04/27 19:44
题目大意:
a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0
所有的变量的范围是【-50,50】,都是整数,求有多少解,也就是多少种情况满足这个等式。
算法分析:
直接循环肯定不行。100的5次方。会超时。考虑到hash。
将等式变形a1x13+ a2x23=- a3x33 -a4x43+-a5x53
求出左边结果保存到hash表中,还好冲突不是太多,二维数组保存冲突的值
然后求出右边的值,查hash表,看看有多少种相同的。将所有相同的加起来就是结果
由于数据范围达到了7位数,所以第一次将数组开到【20000003】【10】,超内存了。后来降低了第一维,可能冲突会多,但是估计数据不是很强,所以就AC了。
代码:
#include <iostream>#include <cstdio>#define mMax 200003using namespace std;int hHash[mMax][10] = {0};int Count(int sSum){int h = 0;int i = sSum % mMax;if (i < 0){i +=mMax;}for (int j = 1; j <= hHash[i][0]; j ++){if (sSum == hHash[i][j]){h ++;}}return h;}void Hash(int sSum){int i;i = sSum % mMax;if (i < 0){i += mMax;}++hHash[i][0];hHash[i][hHash[i][0]] = sSum;}int main(){int a1,a2,a3,a4,a5;int x1,x2,x3,x4,x5;int cnt;while (scanf("%d%d%d%d%d", &a1,&a2,&a3,&a4,&a5) != EOF){cnt = 0;for (x1 = -50; x1 <= 50; x1 ++){if (!x1){continue;}for (x2 = -50; x2 <= 50; x2 ++){if (!x2){continue;}int ssum = a1 * x1 * x1 * x1 + a2 * x2 * x2 * x2;Hash(ssum);}}for (x3 = -50; x3 <= 50; x3 ++){if (!x3){continue;}for (x4 = -50; x4 <= 50; x4 ++){if (!x4){continue;}for (x5 = -50; x5 <= 50; x5 ++){if (!x5){continue;}int sSum = -(a3 * x3 * x3 * x3 + a4 * x4 * x4 * x4 + a5 * x5 * x5 * x5);cnt += Count(sSum);}}}printf("%d\n", cnt);}return 0;}
- poj1840--Eqs
- poj1840 Eqs
- poj1840 Eqs
- Eqs poj1840
- POJ1840-Eqs
- POJ1840:Eqs
- poj1840 - Eqs
- poj1840 Eqs
- POJ1840-Eqs
- poj1840 Eqs
- POJ1840--------Eqs
- [POJ1840]-Eqs
- poj1840 Eqs
- 【POJ1840】Eqs
- poj1840——Eqs
- POJ1840 Eqs(hash)
- POJ1840《Eqs》方法:哈希
- POJ1840 Eqs(hash)
- Top 200的全球开发者BLOG
- 应用程序搜索平台顺势而生
- SAMBA 的实现原理以及使用方法
- windows驱动注册中断服务程序
- CQC与SRSS
- poj1840--Eqs
- linux命令之----ls,bc,tab,ctrl+c,ctrl+d,man,info,whatis,apropos,LANG,locale,nano,who,shutdown,fsck
- Jquery 中 DOM 对象和 jQuery 对象对象的问题
- 互联网创业形态分类
- ubuntu chmsee乱码问题解决
- 装修注意事项
- DOS简单命令小结
- 虚拟机virtualbox:Could not find an open hard disk with UUID {36844126-9e88-4686-9858-2d1a0568f53c}.
- 世界最大的数字优惠券公司