HDU-1496-Equations && POJ-1840-Eqs (hash)
来源:互联网 发布:武汉淘宝产品拍摄 编辑:程序博客网 时间:2024/06/04 00:20
HDU1494:
a*x1^2+b*x2^2+c*x3^2+d*x4^2=0
分块HASH:O(N^4)->O(N^2+N^2)
POJ1840:
a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0
分块HASH:O(N^5)->O(N^2+N^3)
HDU 1496:
//#include <bits/stdc++.h>#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <vector>#include <algorithm>#define INF 0x3f3f3f3fusing namespace std;const int MAXN = 0.4e7+7;const int P = 0.1e7;int hash_[MAXN];int main(){ int a[4]; while(scanf("%d%d%d%d",&a[0],&a[1],&a[2],&a[3])!=EOF) { if(a[0]*a[1]>0 && a[2]*a[3]>0 && a[1]*a[2]>0){printf("0\n");continue;} memset(hash_,0,sizeof(hash_)); int f=0; for(int i=1; i<=100; ++i) for(int j=1; j<=100; ++j) hash_[ i*i*a[0]+j*j*a[1]+P ]++; int ans=0; for(int i=1; i<=100; ++i) for(int j=1; j<=100; ++j) ans+=hash_[ P-i*i*a[2]-j*j*a[3] ]; printf("%d\n",ans*16); } return 0;}
POJ 1840:
//#include <bits/stdc++.h>#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <vector>#include <algorithm>#define INF 0x3f3f3f3fusing namespace std;const int MAXN = 0.25e8+7;const int P = 0.25e8;short hash_[MAXN];int main(){ int a[5]; while(scanf("%d%d%d%d%d",&a[0],&a[1],&a[2],&a[3],&a[4])!=EOF) { memset(hash_,0,sizeof(hash_)); for(int i=-50; i<=50; ++i)if(i!=0) for(int j=-50; j<=50; ++j) { if(j==0)continue; int f=i*i*i*a[0]+j*j*j*a[1]; f=-f; if(f<0)f+=P; hash_[f]++; } int ans=0; for(int i=-50; i<=50; ++i)if(i!=0) for(int j=-50; j<=50; ++j)if(j!=0) for(int k=-50; k<=50; ++k) { if(k==0)continue; int f=i*i*i*a[2]+j*j*j*a[3]+k*k*k*a[4]; if(f<0)f+=P; ans+=hash_[f]; } printf("%d\n",ans); } return 0;}//37 29 41 43 47
0 0
- HDU-1496-Equations && POJ-1840-Eqs (hash)
- hdu 题目1496 Equations , POJ 题目1840 Eqs (整数Hash)
- poj-1840 Eqs(hash)
- Poj 1840 Eqs(Hash)
- POJ 1840Eqs(hash)
- hdu 1496 Equations (hash)
- HDU 1496 Equations(hash)
- (hash)hdu 1496 Equations
- hdu 1496 Equations(hash)@
- POJ 1840 Eqs hash
- POJ-1840 Eqs【Hash】
- poj 1840 Eqs 【hash】
- poj 1840 Eqs , hash
- POJ 1840 Eqs(hash)
- POJ 1840 Eqs(hash)
- POJ 1840 Eqs (hash)
- POJ-1840 Eqs Hash
- poj 1840 Eqs hash
- UIAlertController的使用
- 【转载】SELECT INTO 和 INSERT INTO SELECT 两种 表之间的复制语句
- win32汇编 屏幕截图保存BMP 学习笔记<第一篇>之资料搜集
- socket通信示意图
- openwrt安装mjpg-streamer
- HDU-1496-Equations && POJ-1840-Eqs (hash)
- ubuntu开机直接进入命令行
- c++第五次作业
- 面试中的排序算法总结
- ARM FP寄存器及frame pointer介绍
- GoogleCloudMessage推送的使用二(正式使用走起)
- 仿微信开发(二)--系统语言设置
- MVC流程图
- Codeforces Round #352 (Div. 2),A题与B题题解代码,水过~~