poj 1840 简单哈希
来源:互联网 发布:win7 tcp监听端口阻塞 编辑:程序博客网 时间:2024/06/04 23:27
题意:
给出ai(i=1~5),求a1 * x1^3+ a2 * x2^3+ a3 * x3^3+ a4 * x4^3+ a5 * x5^3=0在-50到50之间的x的解的个数
分析:
把前三个的和放到hash里,然后枚举后两个的和,查一下hash即可。
这题也可以用map去做。
#include<iostream>#include<cstdio>#include<vector>#include<cstring>#include<algorithm>#include<map>using namespace std;const int prime=997;const int l=-50,r=50;vector<int>hs[prime];int main(){ int a[6]; for(int i=1;i<6;i++)scanf("%d",&a[i]); for(int i=l;i<=r;i++) for(int j=l;j<=r;j++) for(int k=l;k<=r;k++){ if(!i||!j||!k)continue; int t=i*i*i*a[1]+j*j*j*a[2]+k*k*k*a[3]; hs[abs(t)%prime].push_back(t); } int ans=0; for(int i=l;i<=r;i++) for(int j=l;j<=r;j++){ if(!i||!j)continue; int t=-(i*i*i*a[4]+j*j*j*a[5]); int id=abs(t)%prime; for(int k=0;k<hs[id].size();k++) if(hs[id][k]==t)ans++; } printf("%d\n",ans); return 0;}
0 0
- poj 1840 简单哈希
- POJ 3349 简单哈希
- poj 2503 简单哈希
- hdu 1496 && poj 1840 (简单哈希)
- poj 1840 简单hash。
- poj 1840 简单hash
- POJ 1840 Eps 简单Hash
- POJ 1200 Crazy Search(简单哈希)
- POJ 1840 Eqs(简单hash入门)
- POJ 1840 折半哈希
- POJ 2528 Mayor's posters 线段树 区间更新 + 简单哈希函数
- POJ 2528——Mayor's posters(线段树+离散化+简单哈希)
- poj 3626 简单bfs
- poj 3126 简单bfs
- poj 3278 简单bfs
- POJ 1323 简单贪心
- POJ 2453 简单模拟
- POJ 2833 简单模拟
- SpringMVC请求的时候是如何找到正确的Controller
- C语言学习笔记----realloc
- 作业:Web应用技术 动态网站
- jquery中attr和prop的区别
- boost::bind的使用方法
- poj 1840 简单哈希
- JavaScript流程控制
- iOS播放Gif方案总结
- 剑指offer(53)-删除链表中重复的结点
- 你可能不知道的C++语法:文本操作符
- JavaWeb开发防止SQL、XSS注入
- poj2676 Sudoku dfs
- leetcode.197. Rising Temperature
- 1. Two Sum