题意: 用0到2^(n+m-1)这2^(n+m-1)个数填在一个2^n*2^m的矩阵里,使得所有相邻的数的二进制表示只有一位不同. Solution: Gray码.对于第i行第j列的数,由i的Gray码左移m位并上j的Gray码得到. #include <cstdio> using namespace std; int n, m, x; int main() { scanf("%d %d",&n,&m); ; i < ( << n); i+…
#!/usr/bin/env python #coding:utf-8 import sys def gray_code(n): if n < 1: return [] n += 1 array = ["0", "1"] for i in xrange(2, n): times = 2 ** (i-1) for j in xrange(times): array.append("1" + array[times-1-j]) for j in…
#!/usr/bin/env python #coding:utf-8 import sys def gray_code(num, array): if num < 1: return if num == 1: array.append('0') array.append('1') return gray_code(num-1, array) times = 2 ** (num-1) len_ = len(array) for i in xrange(times): array.append('…
这几天看了Clifford E. Cummings的两篇大作<Simulation and Synthesis Techniques for Asynchronous FIFO Design>and <Simulation and Synthesis Techniques for Asynchronous FIFO Design with Asynchronous Pointer Comparisons>颇有感想,真可谓经典之作,不可错过. 1.什么是FIFO? FIFO是英文Fi…
Problem Description The reflected binary code, also known as Gray code after Frank Gray, is a binary numeral system where two successive values differ in only onebit (binary digit). The reflected binary code was originally designed to prevent spuriou…
简介 CyclicBarrier 是一个同步辅助工具,允许一组线程全部等待彼此达到共同屏障点,且等待的线程被释放后还可以重新使用,所以叫做Cyclic(循环的). 应用场景 比如出去旅行时,导游需要等待所有的客人到齐后,导游才会给大家讲解注意事项等 官方示例 在JDK的源码注释中,提供了一个简单的示例demo,稍加修改后就可以运行 public class Solver { AtomicInteger sum = new AtomicInteger(0); // 自己新增的一个标识,true代表…
本文大部分内容来自Clifford E. Cummings的<Simulation and Synthesis Techniques for Asynchronous FIFO Design>,同时加上一些自己的一些理解,有兴趣的朋友可以阅读原文. 一.FIFO简介 FIFO是英文First In First Out 的缩写,是一种先进先出的数据缓存器,它与普通存储器的区别是没有外部读写地址线,这样使用起来非常简单,但缺点就是只能顺序写入数据,顺序的读出数据,其数据地址由内部读写指针自动加1完…