POJ 1840(哈希)
来源:互联网 发布:淘宝怎么挣钱 编辑:程序博客网 时间:2024/05/21 17:39
题目链接:http://poj.org/problem?id=1840
看到这道题第一感觉是很熟悉,想起hdu上的一道题。
不过不同的是,这道题如果采用相同方法去做,数组要开始6kw,需要用short开,应该是数据不强吧。
另外,这道题map还可以过。
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<queue>using namespace std;const int INF=0x3f3f3f3f;const int maxn=62500010;const int maxnHash=31250000;int m,t,n;int a1,a2,a3,a4,a5;short hashTable[maxn];int p[50];int main(){#ifndef ONLINE_JUDGEfreopen("test.in","r",stdin);freopen("test.out","w",stdout);#endifwhile(~scanf("%d%d%d%d%d",&a1,&a2,&a3,&a4,&a5)){for(int i=-50;i<=50;i++){if(!i) continue;for(int j=-50;j<=50;j++){if(!j) continue;int tmp=a1*i*i*i+a2*j*j*j;hashTable[tmp+maxnHash]++;}}int ans=0;for(int i=-50;i<=50;i++){if(!i) continue;for(int j=-50;j<=50;j++){if(!j) continue;for(int k=-50;k<=50;k++){if(!k) continue;int tmp=a3*i*i*i+a4*j*j*j+a5*k*k*k;ans+=hashTable[-tmp+maxnHash];}}}printf("%d\n",ans);}return 0;}
附上hdu1496:
Consider equations having the following form:
a*x1^2+b*x2^2+c*x3^2+d*x4^2=0
a, b, c, d are integers from the interval [-50,50] and any of them cannot be 0.
It is consider a solution a system ( x1,x2,x3,x4 ) that verifies the equation, xi is an integer from [-100,100] and xi != 0, any i ∈{1,2,3,4}.
Determine how many solutions satisfy the given equation.
Input
The input consists of several test cases. Each test case consists of a single line containing the 4 coefficients a, b, c, d, separated by one or more blanks.
End of file.
Output
For each test case, output a single line containing the number of the solutions.
Sample Input
1 2 3 -4
1 1 1 1
Sample Output
39088
0
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<queue>using namespace std;const int INF=0x3f3f3f3f;const int maxn=2000010;int a,b,c,d;int Hash[maxn];int p[105];void init(){ for(int i=1;i<=100;i++) p[i]=i*i;}int main(){ init(); while(~scanf("%d%d%d%d",&a,&b,&c,&d)){ if((a>0&&b>0&&c>0&&d>0)||(a<0&&b<0&&c<0&&d<0)){ printf("0\n"); continue; } memset(Hash,0,sizeof(Hash)); for(int i=1;i<=100;i++){ for(int j=1;j<=100;j++){ Hash[(a*p[i]+b*p[j])+1000000]++; } } int sum=0; for(int i=1;i<=100;i++){ for(int j=1;j<=100;j++){ sum+=Hash[-(c*p[i]+d*p[j])+1000000]; } } printf("%d\n",sum*16); } return 0;}
- POJ 1840(哈希)
- POJ 1840 Eqs(哈希)
- poj 1840 Eqs(哈希)
- POJ 1840 Eqs (哈希)
- poj-1840-Eqs 哈希(hash)
- POJ 1840(哈希,数学,思维)
- POJ 1840 (哈希)
- poj 1840 哈希~~~
- Eqs - POJ 1840 哈希
- poj 1840 哈希
- Eqs poj 1840 哈希
- poj 1840 Eqs (哈希)
- POJ 1840 Eqs(哈希)
- poj 1840 (数学)
- POJ 3349 (哈希)
- poj-1840 Eqs 暴力+哈希
- poj 1840 哈希+离散化
- POJ 1840 Eqs(模拟+哈希)
- CentOS6.5 heartbeat高可用集群的详解及工作流程
- 微信企业号开发(4)--管理通讯录(部门)
- HDOJ 2049 不容易系列之(4)——考新郎
- 《机器学习》读书笔记,第二章概念学习和一般到特殊序
- 简析开源网络模块_volley
- POJ 1840(哈希)
- Spring MVC框架小小的理解
- Android关机流程解析
- 数据库设计之三大范式
- Android 顶部带进度条的WebView
- Bootstarp学习(二十三)模态弹出框(Modals)
- kmdf驱动教程2——驱动程序与应用程序通信
- mq:Function not implemented 解决方案
- 寒假集训 1004【最小支配集】