== 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. C#判断操作系统类型

    操作系统  PlatformID  主版本号  副版本号  Windows95  1  4  0  Windows98  1  4  10  WindowsMe  1  4  90  WindowsN ...

  2. POJ 1065 Wooden Sticks(zoj 1025) 最长单调子序列

    POJ :http://poj.org/problem?id=1065 ZOJ: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId= ...

  3. 【TP SRM 703 div2 500】 GCDGraph

    Problem Statement You are given four ints: n, k, x, and y. The ints n and k describe a simple undire ...

  4. 将Sublime Text2 加入右键菜单

    在googleread里面看有人推荐sublime text2.说开发很方便.就下载一个试试.写html还真的挺爽. 于是按照vim加入鼠标右键的方法.果然可以.这里和大家分享 1. 运行中输入 re ...

  5. CentOS7.1 KVM虚拟化之虚拟机快照(5)

    这里用之前克隆的虚拟机vm1-clone进行快照操作 注: 1.快照实际上做的是虚拟机的XML配置文件,默认快照XML文件在/var/lib/libvirt/qemu/snapshot/虚拟机名/下 ...

  6. 关于pptpd log日志文件的配置

    如何开启pptpd默认日志记录功能. 修改/etc/ppp/options.pptpd中的nologfd,默认没有开,把nologfd注释掉,然后添加 logfile /var/log/pptpd.l ...

  7. Hdu4771(杭州赛区)

    Stealing Harry Potter's Precious Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 ...

  8. PHP移动互联网开发笔记(1)——环境搭建及配置

    开篇说明:记得我上大二的时候第一次听到PHP,当时只知道这是一个开发网站的语言,并没有深入学习,在学了Java Web开发和Android开发之后我对互联网的发展方向有了一个我自己的认识,现在我们不能 ...

  9. Android EditText文本内容变化监听方法

    package com.google; import android.app.Activity; import android.os.Bundle; import android.text.Edita ...

  10. Tomcat8及之后版本出现的The valid characters are defined in RFC 7230 and RFC 3986

    升级tomcat8及更高版本带来的问题 由于使用get请求,链接中参数携带特殊字符,由于Tomcat的新版本中增加了一个新特性,就是严格按照 RFC 3986规范进行访问 解析,而 RFC 3986规 ...