HDU 4919 打表找规律 java睑板 map 递归
== 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 递归的更多相关文章
- 数学--数论--HDU - 6322 打表找规律
In number theory, Euler's totient function φ(n) counts the positive integers up to a given integer n ...
- hdu 3032 Nim or not Nim? (SG函数博弈+打表找规律)
Nim or not Nim? Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Sub ...
- HDU 5753 Permutation Bo (推导 or 打表找规律)
Permutation Bo 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5753 Description There are two sequen ...
- HDU 5795 A Simple Nim(SG打表找规律)
SG打表找规律 HDU 5795 题目连接 #include<iostream> #include<cstdio> #include<cmath> #include ...
- 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 ...
- HDU 1021 Fibonacci Again【打表找规律】
Fibonacci Again Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- HDU 4731 Minimum palindrome 打表找规律
http://acm.hdu.edu.cn/showproblem.php?pid=4731 就做了两道...也就这题还能发博客了...虽然也是水题 先暴力DFS打表找规律...发现4个一组循环节.. ...
- 数学--数论--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 ...
- HDU 4861 Couple doubi (数论 or 打表找规律)
Couple doubi 题目链接: http://acm.hust.edu.cn/vjudge/contest/121334#problem/D Description DouBiXp has a ...
随机推荐
- DateTime与timeStamp的转换
DateTime转换为timeStamp: DateTime dt = DateTime.Now; DateTime startTime = TimeZone.CurrentTi ...
- python类继承时构造函数的运行问题
假设子类定义了自己的__init__构造方法函数.当子类的实例对象被创建时,子类仅仅会运行自己的__init__方法函数.假设子类没有定义自己的构造方法函数.会沿着搜索树找到父类的构造方法函数去运行父 ...
- error C2220: warning treated as error - no 'object' file generated warning C4819: The file contains a character that cannot be represented in the current code page (936).
用Visual Studio2015 编译时,遇到如下编译错误: error C2220: warning treated as error - no 'object' file generated ...
- https://github.com/mvf/svn_wfx
https://github.com/mvf/svn_wfx 2003.net对应的vc是7.0版本.需要更高的. 在哪里可以下载呢 https://www.tjupt.org/没有校外种子 Proj ...
- 使用Perl批量读取文件最后行
使用Perl批量读取文件最后行 面对成百上千个文件,有时我们需要查看它的最后行,单个文件打开将耗费大量时间,而通过Perl提取出最后行,将快速的帮助我们处理繁琐的事务. 特性 整个目录完全遍历,自动提 ...
- LIGO找到首个超越广义相对论的证据?
转自 麻省理工科技评论 原文 LIGO找到首个超越广义相对论的证据? 1915年,爱因斯坦根据简单的原理提出广义相对论,极大地改变了人们的时空观.广义相对论不仅解释了牛顿理论无法解释的现象,还做出许多 ...
- 【Lucene4.8教程之五】Luke 2014-06-24 15:12 1092人阅读 评论(0) 收藏
一.Luke基本内容 1.Luke简介 Luke可用于查看Lucene创建的索引,并对其进行基本操作. 2.创建Luke (1)从Github上下载源文件 https://github.com/tar ...
- js进阶 11-15 jquery过滤方法有哪些
js进阶 11-15 jquery过滤方法有哪些 一.总结 一句话总结:jquery方法中的参数一般是什么:选择器.元素或 jQuery 对象. 1.jquery方法中的参数一般是什么? 选择器.元 ...
- event.relatedTarget、event.fromElement、event.toElement
在标准DOM中,mouseover和mouseout所发生的元素可以通过event.target来访问,相关元素通过event.relatedTarget属性来访问.event.relatedTarg ...
- expdp之后scp的惊险时刻
今天在导出数据的时候.忽然就想起了上次导数据的惊险时刻. 当时导出数据,有40g.分盘./backup有几T的空间,非常easy.果断搞! 是daochu.dmp,导出后传到还有一个主机,还有一个主机 ...