== oeis:

点击打开链接

瞎了,x.mod(BigInteger.ValueOf(2)).equal( BigInteger.ValueOf(1))

写成了 x.mod(BigInteger.ValueOf(2)).equal( 1 )

T^T100块没了。。

import java.math.*;
import java.util.*;
import static java.lang.System.out;
import java.io.*;
public class Main {
static Map map = new HashMap<BigInteger, BigInteger>();
static BigInteger x0 = new BigInteger("0");
static BigInteger x1 = new BigInteger("1");
static BigInteger x2 = new BigInteger("2");
static BigInteger x4 = new BigInteger("4");
static BigInteger x6 = new BigInteger("6");
BigInteger dfs(BigInteger x) {
if(map.get(x) != null) return (BigInteger)map.get(x); BigInteger d = dfs(x.divide(x2)); // dfs(x/2)
BigInteger q1 = x.divide(x2); // x/2
BigInteger q2 = q1.subtract(x1); // x/2-1 BigInteger f1;
if (x.mod(BigInteger.valueOf(2)).equals(x1)) {
f1 = d.multiply(x4);
f1 = f1.add(x6.multiply(q1));
} else {
f1 = d;
BigInteger d2 = dfs(q2);
f1 = f1.add(d2);
f1 = f1.add(x);
f1 = f1.subtract(x2);
f1 = f1.multiply(x2);
}
map.put(x, f1);
return f1;
}
public void work() {
map.put(BigInteger.valueOf(0), BigInteger.valueOf(0));
map.put(BigInteger.valueOf(1), BigInteger.valueOf(0));
map.put(BigInteger.valueOf(2), BigInteger.valueOf(0));
map.put(BigInteger.valueOf(3), BigInteger.valueOf(6));
while(cin.hasNext()){
String s = cin.next();
System.out.println(dfs(new BigInteger(s)));
}
}
Main() {
cin = new Scanner(System.in);
}
public static void main(String[] args) {
Main e = new Main();
e.work();
}
public Scanner cin;
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

HDU 4919 打表找规律 java睑板 map 递归的更多相关文章

  1. 数学--数论--HDU - 6322 打表找规律

    In number theory, Euler's totient function φ(n) counts the positive integers up to a given integer n ...

  2. hdu 3032 Nim or not Nim? (SG函数博弈+打表找规律)

    Nim or not Nim? Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Sub ...

  3. HDU 5753 Permutation Bo (推导 or 打表找规律)

    Permutation Bo 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5753 Description There are two sequen ...

  4. HDU 5795 A Simple Nim(SG打表找规律)

    SG打表找规律 HDU 5795 题目连接 #include<iostream> #include<cstdio> #include<cmath> #include ...

  5. HDU 3032 Nim or not Nim?(Multi_SG,打表找规律)

    Nim or not Nim? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  6. HDU 1021 Fibonacci Again【打表找规律】

    Fibonacci Again Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  7. HDU 4731 Minimum palindrome 打表找规律

    http://acm.hdu.edu.cn/showproblem.php?pid=4731 就做了两道...也就这题还能发博客了...虽然也是水题 先暴力DFS打表找规律...发现4个一组循环节.. ...

  8. 数学--数论--HDU 1792 A New Change Problem (GCD+打表找规律)

    Problem Description Now given two kinds of coins A and B,which satisfy that GCD(A,B)=1.Here you can ...

  9. HDU 4861 Couple doubi (数论 or 打表找规律)

    Couple doubi 题目链接: http://acm.hust.edu.cn/vjudge/contest/121334#problem/D Description DouBiXp has a ...

随机推荐

  1. svn 清理失败 (clean up 失败) 的解决方法

    解决方法: step1: 到 sqlite官网 (http://www.sqlite.org/download.html) 下载 sqlite3.exe 找到 Precompiled Binaries ...

  2. 云应用开发之新浪SAE读写云端数据库MySQL

    本博文为前篇博文新浪云应用SAE日志查看的延续. 在读写云数据库MySQL之前,须要说明的是,在新浪云平台上使用数据库时.该平台默认会为每个应用单独新建一个数据库database实例.在该实例中再创建 ...

  3. [RxJS] Replace zip with combineLatest when combining sources of data

    This lesson will highlight the true purpose of the zip operator, and how uncommon its use cases are. ...

  4. hadoop集群中的日志文件 分类: A1_HADOOP 2015-02-28 20:37 680人阅读 评论(0) 收藏

    hadoop存在多种日志文件,其中master上的日志文件记录全面信息,包括slave上的jobtracker与datanode也会将错误信息写到master中.而slave中的日志主要记录完成的ta ...

  5. flash stm32的flash编写

    定义一个全局变量数组:const u8 TEXT_Buffer[]={"STM32F103 FLASH TEST"};    //u8和char* 写入到内存里会有什么区别???? ...

  6. php 静态方法和非静态方法的调用说明

    1. php类中,静态方法调用当前类的非静态方法必须用self关键字,不能用$this 2. php类中,公有方法调用私有方法使用$this关键字,只能实例化调用 3. php类中,公有方法调用私有方 ...

  7. win-server下定时备份oracle数据库实现方法

    1.在e盘建立一个“oracle_backup”的文件夹,文件夹下再建两个文件夹分别为:“new”,“old”,然后在oracle_backup文件夹中新建一个bat文件,取名“expdb.bat”, ...

  8. 【35.43%】【hdu 4347】The Closest M Points

    Time Limit: 16000/8000 MS (Java/Others)    Memory Limit: 98304/98304 K (Java/Others) Total Submissio ...

  9. 【23.58%】【code forces 321E】Ciel and Gondolas

    time limit per test4 seconds memory limit per test512 megabytes inputstandard input outputstandard o ...

  10. catalina.out 和 catalina.log 的区别和用途

    catalina.out catalina.out其实是tomcat的标准输出(stdout)和标准出错(stderr),这是在tomcat的启动脚本里指定的,如果没有修改的话stdout和stder ...