== 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. 【数学】概念的理解 —— 有序对(ordered pair)

    有序对 (a,b) 是一组对象,不同的顺序意味着不同的对象,(a,b)≠(b,a) 除非 a=b,正是因为对象的相对顺序是有着不同含义的,因此有时也称之为 2 维向量.与之相对的无序对(unorder ...

  2. 解决java中ZipFile解压缩时候的中文路径和乱码问题

    JAVA中对jar文件或zip文件解压的时候,能够使用JDK内置的API:JarFile和ZipFile,在windows下解压这2种格式文件的时候,常常报下面错误: Exception in thr ...

  3. PWA之消息推送——Notification

    原文 简书原文:https://www.jianshu.com/p/69042b92cae1 大纲 1.推送通知的概念 2.消息推送的知识点 3.实例 1.推送通知的概念 大部分现代 Web 应用都需 ...

  4. CSS边框作图

    原文 简书原文:https://www.jianshu.com/p/537a878304f2 大纲 1.border-style的值 2.利用border作图——基本图形 3.利用border作图—— ...

  5. 在Scope利用Content sharing Widget来分享内容

    在最新的Scope Widget中,有一个新的Content Sharing Widget.我们能够利用这个Widget来分享我们的图片到信息.Facebook,Twitter等渠道.比方,在我们的S ...

  6. Android自定义组件系列【6】——进阶实践(3)

    上一篇<Android自定义组件系列[5]--进阶实践(2)>继续对任老师的<可下拉的PinnedHeaderExpandableListView的实现>进行了分析,这一篇计划 ...

  7. <Linux> Xen虚拟机镜像的安装

    了解系统安装在哪个磁盘上:fdisk -l 建立存放虚拟机镜像的目录:mkdir /mnt/vmx 更改文件系统格式: mkfs -t ext4 /dev/sda或者/dev/sdb(系统不在的那个硬 ...

  8. https://sourceware.org/gdb/onlinedocs/gdb/Forks.html

    https://sourceware.org/gdb/onlinedocs/gdb/Forks.html Next: Checkpoint/Restart, Previous: Threads, Up ...

  9. PEM_密钥对生成与读取方法

    PS:欢迎转载,但请注明出处,谢谢配合. 前言: PEM是OpenSSL和许多其他SSL工具的标准格式,OpenSSL 使用PEM 文件格式存储证书和密钥.这种格式被设计用来安全的包含在ascii甚至 ...

  10. oracle改动登录认证方式

    通过配置sqlnet.ora文件.我们能够改动oracle登录认证方式. SQLNET.AUTHENTICATION_SERVICES=(NTS);基于操作系统的认证 SQLNET.AUTHENTIC ...