== 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. SIMPLE QUERY几个原则

    1.减少查询对象的数据页(db block)数量. 尽量避免使用 * 用准确的列明减少不必要的一些资源浪费.   2.查看是否使用了index. 索引是SQL性能调优的重要手段,下面几个是有索引不能使 ...

  2. POJ 3211 Washing Clothes 0-1背包

    题目大意: xxx很懒,但他有个漂亮又勤奋的女友 (尼玛能不能不刺激我,刚看到这题的时候发现自己的衣服没洗!!!) 可以帮他洗衣服. 洗衣服的时候要求不同的颜色的衣服不能同时洗.一人洗一件的话,问最短 ...

  3. Codeforces 467C. George and Job

    DP.... C. George and Job time limit per test 1 second memory limit per test 256 megabytes input stan ...

  4. Angular 2 HostListener & HostBinding

    原文 https://www.jianshu.com/p/20c2d60802f7 大纲 1.宿主元素(Host Element) 2.HostListener 3.HostListenerDecor ...

  5. 安装Win10+Ubuntu14.04双系统(uefi启动版)

    说明 本教程基于个人电脑(型号:神舟K550d-i7 D1)成功安装测试发布,不同硬件环境可能有细微差异,为预防安装过程中出现意想不到的报错,重要数据请提前备份 硬件环境 cpu:Intel i7-4 ...

  6. js进阶 11-16 jquery如何查找元素的父亲、祖先和子代、后代

    js进阶 11-16 jquery如何查找元素的父亲.祖先和子代.后代 一.总结 一句话总结:过滤或者查找的方法里面可以带参数进行进一步的选择. 1.parent()和parents()方法的区别是什 ...

  7. [React Router v4] Redirect to Another Page

    Overriding a browser's current location without breaking the back button or causing an infinite redi ...

  8. [Angular] Ngrx/effects, Action trigger another action

    @Injectable() export class LoadUserThreadsEffectService { constructor(private action$: Actions, priv ...

  9. Net Core 实现谷歌翻译ApI 免费版

    原文:Net Core 实现谷歌翻译ApI 免费版 由于谷歌翻译官方API是付费版本,本着免费和开源的精神.分享一下用 Net Core 实现谷歌翻译API的代码. 项目引用的Nuget 包: Cha ...

  10. js调用百度地图api

    <!DOCTYPE html> <html>     <head>         <meta charset="UTF-8">   ...