0%

懒汉式

​ 需要使用时再加载

1
2
3
4
5
6
7
8
9
10
11
12
13
public class SingleInstanceLazy {

private static SingleInstanceLazy instance;

private SingleInstanceLazy(){}

public static synchronized SingleInstanceLazy getInstance(){
if (instance == null) {
instance = new SingleInstanceLazy();
}
return instance;
}
}
阅读全文 »

​ 哈利·波特要考试了,他需要你的帮助。这门课学的是用魔咒将一种动物变成另一种动物的本事。例如将猫变成老鼠的魔咒是haha,将老鼠变成鱼的魔咒是hehe等等。反方向变化的魔咒就是简单地将原来的魔咒倒过来念,例如ahah可以将老鼠变成猫。另外,如果想把猫变成鱼,可以通过念一个直接魔咒lalala,也可以将猫变老鼠、老鼠变鱼的魔咒连起来念:hahahehe。

阅读全文 »

​ 给定一个有N个顶点和E条边的无向图,请用DFS和BFS分别列出其所有的连通集。假设顶点从0到N−1编号。进行搜索时,假设我们总是从编号最小的顶点出发,按编号递增的顺序访问邻接点。

输入格式:

​ 输入第1行给出2个整数N(0<N≤10)和E,分别是图的顶点数和边数。随后E行,每行给出一条边的两个端点。每行中的数字之间用1空格分隔。

阅读全文 »

​ We have a network of computers and a list of bi-directional connections. Each of these connections allows a file transfer from one computer to another. Is it possible to send a file from any computer on the network to any other?

Input Specification:

​ Each input file contains one test case. For each test case, the first line contains N (2≤N≤104), the total number of computers in a network. Each computer in the network is then represented by a positive integer between 1 and N. Then in the following lines, the input is given in the format:

阅读全文 »

​ Given a tree, you are supposed to list all the leaves in the order of top down, and left to right.

Input Specification:

​ Each input file contains one test case. For each case, the first line gives a positive integer N (≤10) which is the total number of nodes in the tree – and hence the nodes are numbered from 0 to N−1. Then N lines follow, each corresponds to a node, and gives the indices of the left and right children of the node. If the child does not exist, a “-“ will be put at the position. Any pair of children are separated by a space.

阅读全文 »

结构 - 边 ENode - PtrToENode - Edge

  1. 1.无向边(V1,V2),V1 V2为顶点
  2. 权重Weight

结构 - 邻接点 AdjVNode - PtrToAdjVNode

  1. 邻结点下标AdjV
  2. 邻结点权重Weight
  3. 下一个邻接点Next
阅读全文 »

结构 - 图结点 GNode - PtrToGNode - MGraph

  1. 顶点数Nv
  2. 边数Ne
  3. 邻接矩阵二维数组G
  4. 顶点数据Data
阅读全文 »

​ Given a stack which can keep M numbers at most. Push N numbers in the order of 1, 2, 3, …, N and pop randomly. You are supposed to tell if a given sequence of numbers is a possible pop sequence of the stack. For example, if M is 5 and N is 7, we can obtain 1, 2, 3, 4, 5, 6, 7 from the stack, but not 3, 2, 1, 7, 5, 6, 4.

阅读全文 »

设计函数分别求两个一元多项式的乘积与和。

输入格式:

输入分2行,每行分别先给出多项式非零项的个数,再以指数递降方式输入一个多项式非零项系数和指数(绝对值均为不超过1000的整数)。数字间以空格分隔。

阅读全文 »