poj 1840 哈希+离散化
来源:互联网 发布:java工作描述怎么写 编辑:程序博客网 时间:2024/05/20 21:57
点击打开链接
#include <iostream>#include <algorithm>#include <cstring>using namespace std;const int M =12500000;short hash[M*2+10];//给出coefficients ai 求 a1 X1^3 + a2 X2^3 + a3X3^3 + a4X4^3 + a5 X5^3=0 的解个数 xi∈[-50,50] xi != 0 // 暴力枚举 5个循环 10^10 肯定TLE // 所以变形 a3X3^3 + a4X4^3 + a5 X5^3=-(a1 X1^3 + a2 X2^3)// 枚举右边的和并保存在HASH中 O(n^2) 在暴力枚举左边的和 O(n^3) 看在HAsh中是否存在即可 int main(){int a1,a2,a3,a4,a5;cin>>a1>>a2>>a3>>a4>>a5;memset(hash,0,sizeof(hash));for(int x1=-50;x1<=50;x1++){if(!x1) continue;//xi !=0 for(int x2=-50;x2<=50;x2++){if(!x2) continue;int t1=a1*x1*x1*x1;int t2=a2*x2*x2*x2;long sum=-1*(t1+t2); // -M <=sum<=M if(sum<0)sum+=M*2; // 下标不为负数 离散化后 负数sum: M<sum<2M hash[sum]++; // a+b=sum x1=a,x2=b 和x1=b,x2=a 视为不同解 }}int ans=0;for(int x3=-50;x3<=50;x3++){if(!x3) continue;for(int x4=-50;x4<=50;x4++){if(!x4) continue;for(int x5=-50;x5<=50;x5++){if(!x5) continue;long sum=a3*x3*x3*x3+a4*x4*x4*x4+a5*x5*x5*x5;if(sum<0)sum+=M*2;ans+=hash[sum];}}}cout<<ans<<endl;return 0;}
0 0
- poj 1840 哈希+离散化
- poj 1151 离散化
- 【RMQ+离散化】POJ 3368
- poj 3386 RMQ+离散化
- [离散化+线段树] POJ
- POJ 2528 线段树+坐标离散化+哈希+二分
- poj 2417 离散对数模方程+哈希
- POJ 1151 Atlantis 线段树+离散化
- poj 3368 离散化+线段树
- poj 2528 线段树+离散化
- POJ 2528 (线段树+离散化)
- POJ 2299 树状数组+离散化
- poj 2528 (线段树+离散化)
- POJ 1106 Transmitters(离散化)
- poj~2528~离散化线段树
- poj 2528 线段树成段更新+离散化
- POJ 3277 离散化线段树
- poj 2299 树状数组+离散化
- 排序算法总结---java面试
- USB调试实现
- JAVA自学之每日一题(六)
- springmvc导入导出
- 虚幻4蓝图使用小技巧(更新)
- poj 1840 哈希+离散化
- Codeforces Round #361 (Div. 2) -- A. Mike and Cellphone (思路题目)
- 经常逛的网站,持续更新
- 解决Mac AndroidStudio无法关联源码问题
- 关于Fragment的一点小技巧
- Android_将RecyclerView打造成自己SwipeRecyclerView
- Android中线程同步之Mutex与Condtion的用法
- 教你快速掌握androidstudio使用git上传本地项目到github、版本控制
- 正则表达式学习笔记(一)全部符号解释