bcd

BCD Code ZOJ - 3494 AC自动机+数位DP

我与影子孤独终老i 提交于 2019-11-27 22:03:05
题意: 问A到B之间的所有整数,转换成BCD Code后, 有多少个不包含属于给定病毒串集合的子串,A,B <=10^200,病毒串总长度<= 2000. BCD码这个在数字电路课上讲了,题干也讲的很详细。 数位DP的实现是通过0~9 ,并不是通过BCD码 所有我们需要先把字串放入AC自动机,建立一个BCD数组 因为BCD码是一个4位二进制数,但是tire图上全是0,1, 所以对于一个数字,我们的要在转移4次, 如果中间出现了病毒串就return -1 表示不能转移, BCD【i】【j】表示在AC自动机 i 这个节点转移到数字 j 对应的在AC自动机上的节点标号。 然后就是简单的数位DP了,然而我写搓了,由于没有前导0所以前导0要处理掉。 但是你不转移的时候,不能 bcd[idx][i] != -1 就直接continue , 因为有0的情况,i==0 但是(bcd[idx][i] == -1) 但是这个0是前导0所以不影响。 1 #include <set> 2 #include <map> 3 #include <stack> 4 #include <queue> 5 #include <cmath> 6 #include <ctime> 7 #include <cstdio> 8 #include <string> 9 #include <vector> 10

Convert 8bit binary number to BCD in VHDL

前提是你 提交于 2019-11-27 09:38:26
The algorithm is well known, you do 8 left shifts and check the units, tens or hundreds bits (4 each) after each shift. If they are above 4 you add 3 to the group and so on... Here is a process based solution that does not work. It will compile but the output is not what I wanted. Any thoughts what could be the problem? library ieee ; use ieee.std_logic_1164.all ; use ieee.std_logic_unsigned.all ; entity hex2bcd is port ( hex_in : in std_logic_vector (7 downto 0) ; bcd_hun : out std_logic_vector (3 downto 0) ; bcd_ten : out std_logic_vector (3 downto 0) ; bcd_uni : out std_logic_vector (3

Unsigned Integer to BCD conversion?

北慕城南 提交于 2019-11-27 07:54:24
问题 I know you can use this table to convert decimal to BCD: 0 0000 1 0001 2 0010 3 0011 4 0100 5 0101 6 0110 7 0111 8 1000 9 1001 Is there a equation for this conversion or you have to just use the table? Im trying to write some code for this conversion but Im not sure how to do the math for it. Suggestions? 回答1: You know the Binary numeral system, don't you? Especially have a look at this chapter. EDIT: Also note KFro's comment that the lower nibble (= 4 bits) of the binary ASCII representation

java中的正则表达式(一)

徘徊边缘 提交于 2019-11-26 16:18:06
最近在学习springMVC的源码并尝试从零开发一下web框架。在学习用遇到了一个拦路虎————正则表达式。在我平时的开发工作中对于正则表达式的使用并不是很频繁,可以说是几乎不用,即使用到了都是通过上网百度查询,久而久之正则表达式成了我的短板(虽然这块短板还没有影响我的工作)。在看了springMVC的框架后发现,其实正则表达式在封装框架中起着至关重要的作用,因此熟练的掌握正则表达式可以帮助我们学习底层的代码逻辑。 正则表达式:是一串字符,它描述了一种文本模式。这句话取自java编程的逻辑。正则表达式中的字符有两类,一类是普通字符用来匹配其本身,一类是元字符,这类字符有特殊的含义。这里需要注意一点,正则表达式有它自己的语法,许多的编程语言都支持正则表达式但是可能不同的语言对于正则表达式的语法解析是不同的,这里我介绍的是java中的正则表达式。 1.单个字符 绝大多数单个字符表示的就是其本身例如:‘A’,'B','C'。但是有一些字符是需要多个字符表示的,比如‘\n’换行 '\t'tab键。以八进制表示的字符要以‘\0’后面跟1~3位数字,以十六进制表示的字符要以‘\x’开头后面跟两个字符,以Unicode编号表示的字符要以‘\u’开头后面跟4个字符。在正则表达式中还有一些元字符:?、*、. 需要表示这些字符本身需要使用‘\’来转义例如:‘\?’,如果需要表示反斜杠本身需要'\\

Convert 8bit binary number to BCD in VHDL

大兔子大兔子 提交于 2019-11-26 14:48:14
问题 The algorithm is well known, you do 8 left shifts and check the units, tens or hundreds bits (4 each) after each shift. If they are above 4 you add 3 to the group and so on... Here is a process based solution that does not work. It will compile but the output is not what I wanted. Any thoughts what could be the problem? library ieee ; use ieee.std_logic_1164.all ; use ieee.std_logic_unsigned.all ; entity hex2bcd is port ( hex_in : in std_logic_vector (7 downto 0) ; bcd_hun : out std_logic