Map的应用(节省空间和时间)
来源:互联网 发布:网络渗透软件 编辑:程序博客网 时间:2024/05/01 10:19
package 解析URL;
import java.math.BigInteger;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
public class 优化的阶乘计算 {
static Map<BigInteger, BigInteger> map=new HashMap<BigInteger, BigInteger>();
public static void main(String[] args){
map.clear();
Random random=new Random();
for(int i=0;i<10;i++)
{
int ranInt=random.nextInt(10);
System.out.println(ranInt);
System.out.println(fuck(BigInteger.valueOf(ranInt)));
System.out.println("*****************");
}
System.out.println("000000000000000000000000000000000000000");
athot();
}
private static BigInteger fuck(BigInteger value) {
if(value.compareTo(BigInteger.valueOf(0))==0){
return BigInteger.valueOf(1);
}else{
//从缓存中查找
BigInteger factor=(BigInteger)map.get(value);
if(factor!=null){
System.out.println("-------------这个是在集合中取的==============");
return factor;
}
BigInteger nplusOne=value.subtract(BigInteger.valueOf(1));
factor=fuck(nplusOne).multiply(value);
map.put(value, factor);
return factor;
}
}
private static void athot() {
java.util.Iterator<Entry<BigInteger, BigInteger>> iter = map.entrySet().iterator();
while (iter.hasNext()) {
@SuppressWarnings("rawtypes")
Map.Entry entry = (Map.Entry) iter.next();
System.out.println(entry.getKey()+" --> "+entry.getValue());
//System.out.println(entry.getValue());
}
}
}
import java.math.BigInteger;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
public class 优化的阶乘计算 {
static Map<BigInteger, BigInteger> map=new HashMap<BigInteger, BigInteger>();
public static void main(String[] args){
map.clear();
Random random=new Random();
for(int i=0;i<10;i++)
{
int ranInt=random.nextInt(10);
System.out.println(ranInt);
System.out.println(fuck(BigInteger.valueOf(ranInt)));
System.out.println("*****************");
}
System.out.println("000000000000000000000000000000000000000");
athot();
}
private static BigInteger fuck(BigInteger value) {
if(value.compareTo(BigInteger.valueOf(0))==0){
return BigInteger.valueOf(1);
}else{
//从缓存中查找
BigInteger factor=(BigInteger)map.get(value);
if(factor!=null){
System.out.println("-------------这个是在集合中取的==============");
return factor;
}
BigInteger nplusOne=value.subtract(BigInteger.valueOf(1));
factor=fuck(nplusOne).multiply(value);
map.put(value, factor);
return factor;
}
}
private static void athot() {
java.util.Iterator<Entry<BigInteger, BigInteger>> iter = map.entrySet().iterator();
while (iter.hasNext()) {
@SuppressWarnings("rawtypes")
Map.Entry entry = (Map.Entry) iter.next();
System.out.println(entry.getKey()+" --> "+entry.getValue());
//System.out.println(entry.getValue());
}
}
}
0 0
- Map的应用(节省空间和时间)
- hadoop和hive压缩格式对比【数据源建议RCFile+bz或RCFile+gz的方式可以节省空间,计算过程建议RCFile+snappy,空间换时间】
- 联合:节省空间的类
- FINAL的使用节省时间
- mysql节省时间的命令
- 节省空间
- 节省时间
- 请设计一个既节省时间又节省空间的算法来找出该链表中的倒数第m个元素
- 求空间节省比例的方法
- C/C++语言里面的空间节省
- union:一种节省空间的类
- 一个节省空间的小技巧
- union: 一种节省空间的类
- 节省空间的结构:BitMap(位图)
- 45分钟会议:节省时间和钱!
- iOS常用宏,节省时间和精力
- 为你节省时间和挫败感
- UVA11168凸包的应用之使用解析几何巧妙节省时间
- 引用和const引用(笔记)
- POJ 1014 Dividing 这算是优化吗
- Qt模块化笔记之network——TcpServer与监听说明
- Java(二)Java程序设计环境
- 什么是无纺布?无纺布有什么用途?什么是不织布?
- Map的应用(节省空间和时间)
- const int function(const int a,const int b) const的意义
- 冬季热车的注意事项
- 解决隐式声明与内建函数不兼容问题
- 重写Equals方法
- 动态绑定(多态)
- 接口的简单应用
- 黑马程序员_JAVA学习笔记12
- SqlParameter[]写法