2013
11-09

# Binary codes

Consider a binary string (b1…bN) with N binary digits. Given such a string, the matrix of Figure 1 is formed from the rotated versions of the string.

 b1 b2 … bN−1 bN b2 b3 … bN b1 … bN−1 bN … bN−3 bN−2 bN b1 … bN−2 bN−1

The first line contains one integer N ≤ 3000, the number of binary digits in the binary string. The second line contains N integers, the binary digits in the last column from top to bottom.

The first line contains N integers: the binary digits in the first row from left to right.

5
1 0 0 1 0

0 0 0 1 1

//* @author:
import java.io.*;
import java.util.*;
public class Main {
static public void main(String[] args) {
Scanner cin = new Scanner(System.in);
int n;
n = cin.nextInt();
int i, j;
int[] next = new int[3003];
int[] a = new int[3003];
int[] b = new int[3003];
boolean[] used = new boolean[3003];
int ones = 0;
for (i=0; i< n; i++) used[i] = false;
for (i=0; i< n; i++) {
a[i] = cin.nextInt();
ones += a[i];
}
for (i=0; i< n-ones; i++) b[i] = 0;
for (i=n-ones; i< n; i++) b[i] = 1;
j = 0;
for (i=0; i< n; i++) {
while (b[i] != a[j] || used[j]) j++;
used[j] = true;
next[i] = j;
j = 0;
}
j = 0;
j = next[j];
System.out.print(a[j]);
for (i=1; i< n; i++) {
j = next[j];
System.out.print(" " + a[j]);
}
}
}

1. 问题3是不是应该为1/4 .因为截取的三段，无论是否能组成三角形， x， y-x ，1-y,都应大于0，所以 x<y,基础应该是一个大三角形。小三角是大三角的 1/4.

2. 第一题是不是可以这样想，生了n孩子的家庭等价于n个家庭各生了一个1个孩子，这样最后男女的比例还是1:1

3. 第2题，TCP不支持多播，多播和广播仅应用于UDP。所以B选项是不对的。第2题，TCP不支持多播，多播和广播仅应用于UDP。所以B选项是不对的。