Category: 计算机与 Internet


Java tips

  1. FileUtils.wirteStringToFile(…)是否支持多线程?
  2. 比如多个线程写同一文件

    https://stackoverflow.com/questions/13463662/java-library-like-org-apache-commons-io-fileutils-but-contains-instance-methods

    这个link的答复似乎是不支持

    However if you try e.g. to write to the same file from within multiple threads you may have some problems.

    但在windows上测试的结果是没有问题的,似乎FileOuputStream的内部实现,自动同步了多个线程race condition

  3. class static variable initialization
    there are 2 ways to init a class static variable:
  4. public static int mB=10;   //way1
    static {
        mB=5;                          //way2
    }
    which one is done firstly? way1, so way2 will override way1.

          

  5. Usage of HashMap, Hashtable, ConcurrentHashMap
    单线程 情况下用HashMap;multithreads强调synchronization用Hashtable,因为Hashtable是对整个map锁定; multithreads强调效率,用ConcurrentHashMap,因为它仅对部分数据结构锁定;
  6.      

  7. Lambda expression
    Lambda表达式也不是什么新东西,一句话概括就是实现只有1个abstract method的interface         
            lambda-expression
  8. import Java.util.*;
    public class GFG {
     
        public static void main(String[] args) throws Exception
        {
     
            List<String> arr1 = new ArrayList<String>();
             int count = 0;
            arr1.add("Geeks");
            arr1.add("For");
             arr1.add("Geeks");
            arr1.stream().forEach(s -> {       
             
                // print all elements
                 System.out.print(s);
            });
        }
    }
    forEach中就是1个Lambda表达式,实现了Consumer接口中的accept(T) method,Consumer中唯一的abstract method

  9. NaN of double
    assuming d is a double, boolean expression d==Double.NaN always return false even if d==Double.NaN
    Instead Double.isNaN(d) should be used
  10. This is a vb tip to handle char “
    Dim dq As String
    dq = """123"     ‘”” is used to parse “
    Anad the result is to get a string “123
  11. Rmi
    Surely there is an rmi thread pool to execute object methods. So for each call to obj.method(), should jvm fork a new thread to execute it? No, for each call of registry.lookup(url) in client’s thread A, a stub is returned. Subsequent calls to stub.method() in this client’s thread A will all be executed in same server thread.

http://baijiahao.baidu.com/s?id=1632151660141484205

要点就是:

  1. n个量子位能同时编码(0,2^n-1)共2^n个数
  2. 但某个时刻只能观测(读取和写入)这2^n个数字中的某一个
    即这些数以某种概率出现(被读取和写入),总和为1

不过它没回答,这些数对应的概率是怎么被确定下来的?

那么对于一台32位拥有4G内存的传统计算机来说,它符合前提1;

另外只要满足一定条件,符合前提2也是可以的。

所以可以认为一台32位4G内存传统计算机可以模拟一组32个量子位。

n台32位4G内存传统计算机可以模拟n组32个量子位。

    Maybe we can be put into a system,and be represented as be a number。

    This number indicates what we are and describes what we shall do in next step。

    So is there a rational number for a human?

    In mathematics, irrational number means non-cycle limitless number.

    Since a human is always of limit(his life is limited), he is always a rational number if it can be encoded a number.

    (These are 2 different concepts, a human’s limited life and his encoded number’s length are different)

    note20180310:

    1. Maybe not a number, but a group of independent numbers
    2. Maybe a group of both independent and dependent numbers
    3. Could these independent and dependent numbers be encoded as a number?

    很显然,需要对它的技术做修改。

    所谓深度学习技术,其实是一种自下而上的技术,通过输入大量的数据,结合神经网络,总结出规律(总结出1个函数?函数拟合?)。

    对于1个天才来说,它本身不需要学习。

    深度学习技术,不过是把天才的行为函数化(自动化?系统化?)罢了,或者说解密天才的行为。

    有意思的是,alphago团队本身并无1个围棋的职业选手,只有黄士杰是个业余n段兼围棋开发者;而且当5翻棋第4局出现bug之后,alphago的创造者回答提问也很有意思,“他们也不晓得alphago是如何学习的?”

    alphago创造者虽然创造了alphago,但alphago的执行能力强于创造者,而且alphago的具体执行过程甚至创造者都未必能100%掌控。

     

    This is an ugly spyware when u install something from untrusted source.

    One key sympton is that when u open default browser, a default url is opened  http://www.hao601.com/?tn5_9_30=27711

    Even if u set default home URL to about:blank, that URL is still opened.

    In fact, it is implemented by appending that URL to ur browser’s quick start URL. So right click ur browser icon, property, remove “http://www.hao601.com/?tn5_9_30=27711” from target.

    任给1棵树,都可以用表格来表示。

     

    同样,任给1表格,也可以用树来表示。

    http://news.163.com/special/tuling002/#!/scene-1

    average

    How many kinds of average number are there for a value depending on time series?

    1. simple moving average
    2. cumulative moving average
    3. weighted moving average
    4. exponential weighted moving average

    Others?

    EWMA is a very interesting one.

    取石子游戏

    Description

    有两堆石子,数量任意,可以不同。游戏开始由两个人轮流取石子。游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子;二是可以在两堆中同时取走相同数量的石子。最后把石子全部取完者为胜者。现在给出初始的两堆石子的数目,如果轮到你先取,假设双方都采取最好的策略,问最后你是胜者还是败者。

    Input

    输入包含若干行,表示若干种石子的初始情况,其中每一行包含两个非负整数a和b,表示两堆石子的数目,a和b都不大于1,000,000,000。

    Output

    输出对应也有若干行,每行包含一个数字1或0,如果最后你是胜者,则为1,反之,则为0。

     

    assuming input is (a, b), a is alway less than b, say a to be part0, say b to part1

    1. if a = b,print 1
    2. if (a,b) = (1,2) , print 0
    3. if (a,b) = (1,n), n>2
      firstly get n-2, then it can be reduced to scenario 2
      so print
      1
    4. if (a,b) = (2, n), n>2
      if I get 1from part0, it is reduced to (1,n), so I lose. excluding it
      if I get 2 from part0, it is reduced to (0,n), so I lose, excluding it
      So I can only get from part1. get n-1 from part1, reduce it to scenario 2
      so print
      1
    5. if (a,b) = (3, n), n>3
      can not get 1, or 2, or 3 from part0, it will lose   
          if n=4, (3,4) reduce to (3,3), lose
                      (3,4) reduce to (3,2), lose
                      (3,4) reduce to (3,1), lose
                      (3,4) reduce to (3,0), lose
                print 0 for (3,4)
          if n>4, reduce (3,n) to (3,4) by get n-4 from part1
                print 1 for (3,n) n>4
    6. if (a,b) = (4, n), n>4
      (4,n) reduce to (4,3) by get n-3 from part1
      print 1
    7. if(a,b) = (5, n), n>5
      can not get 1,2,3,4,5 from part0, will lose
    8.     if n=6, (5,6) reduce to (5,5), lose
                      (5,6) reduce to (5,4), lose
                      (5,6) reduce to (5,3), lose
                      (5,6) reduce to (5,2), lose
                      (5,6) reduce to (5,1), lose
                      (5,6) reduce to (5,0), lose
                print 0 for (5,6)
          if n>6, reduce (5,n) to (5,6) by get n-6 from part1
                print 1 for (5,n) n>6

    9. if(a,b) = (6, n), n>6
      (6,n) reduce to (6,5) by get n-5 from part1
      print 1

    So we can see something here, summarize as such:

     

    • if a=b, ouput 1
    • sort the pair to be (a,b) to meet a<b
      if a=2n, output 1
      if a=2n+1, b=2n+2, output 0
      if a=2n+1, b>2n+2, output 1
    0 n 1
    1 2 0
    1 n(>2) 1
    2 n(>2) 1
    3 4 0
    3 n(>4) 1
    4 n(>4) 1
    5 6 0
    5 n(>6) 1
    6 n(>6) 1
    7 8 0
    7 n(n>8) 1

      Yellow means they can be changed as required.

    1. Next State
      image
      Input State Input Symbol Output State Output Symbol Action
      S0 i0 S1 i0 0
    2. If then else
      image
      Input State Input Symbol Output State Output Symbol Action
      S0 i0 S1 i0 0
      S0 i1 S2 i1 0
    3. empty Loop
      S0: initial
      S1: loop body start
      S2: loop body end 
      image

      Turing machine Tape Initials:        image

      Input State Input Symbol Output State Output Symbol Action
      S0 0 S1 1 R
      S0 1 S1 2 R
      S0 S1 R
      S0 n-1 S1 n R
      S0 n Sout    
      S1 !FlagS1 S1 FlagS1 0
      S1 FlagS1 S2   R
      S2 any S2   L
      S2 FlagS1 S0 !FlagS1 L
    4. Loop with something between S1 and S2
      Take a look at the red entry at above table, modify S2 to others, and make sure there is a new entry of returning to S2 after ur loop body logic
      Input State Input Symbol Output State Output Symbol Action
      S1 FlagS1 Others   R
        S2   R
      S2 any S2   L
      S2 FlagS1 S0 !FlagS1 L
    5. Copy of A String 111…111
      Input State Input Symbol Output State Output Symbol Action
      S0 0 Sout    
      S0 1 S1 Flag R
      S1 1 S1   R
      S1 0 S2   R
      S2 1 S2   R
      S2 0 S3 1 L
      S3 any-Flag S3   L
      S3 Flag S0 1 R
    6. Append a String 111…111 to a String 111…111||null 
      identical to 5,here is its flow graph
      image
    7. Multiplication
      sample:
       image

      Input State Input Symbol Output State Output Symbol Action Comment
      S0 0 Sout     exception
      S0 1 S1   R  
      S1 0 S6   R S6=start moving to the end and add the tailing 1
      S1 1 S2 Flag R  
      S2 1 S2   R  
      S2 0 S3   R complete reading 1st number
      S3 0 Sout     exception
      S3 1 S4   R  
      S4   S5     append following 1s to subsequent 1s
      S5 any-Flag S5   L  
      S5 Flag S1 1 R  
      S6 1 S7   R  
      S6 0 Sout     exception
      S7 1 S7   R  
      S7 0 S8   R complete reading 2nd number
      S8 1 S8   R  
      S8 0 Sout 1   normal