Einsturing

仅余我与暮色平分此世界


  • 首页

  • 关于

  • 标签

  • 分类

  • 归档

  • 搜索

Poj1321 棋盘问题

发表于 2018-09-20 | 更新于: 2019-02-16 | 分类于 Algorithm , Search , Depth First Search |
字数统计: 437 | 阅读时长 ≈ 1

Description

在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别。要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的摆放方案C。

Input

输入含有多组测试数据。 每组数据的第一行是两个正整数,n k,用一个空格隔开,表示了将在一个n*n的矩阵内描述棋盘,以及摆放棋子的数目。 n <= 8 , k <= n 当为-1 -1时表示输入结束。 随后的n行描述了棋盘的形状:每行有n个字符,其中 # 表示棋盘区域, . 表示空白区域(数据保证不出现多余的空白行或者空白列)。

Output

对于每一组数据,给出一行输出,输出摆放的方案数目C (数据保证C<2^31)。

Sample Input

1
2
3
4
5
6
7
8
9
2 1
#.
.#
4 4
...#
..#.
.#..
#...
-1 -1

Sample Output

1
2
2
1
阅读全文 »

Poj1014 Dividing

发表于 2018-09-18 | 更新于: 2019-02-16 | 分类于 Algorithm , Search , Depth First Search |
字数统计: 577 | 阅读时长 ≈ 3

Description

Marsha and Bill own a collection of marbles. They want to split the collection among themselves so that both receive an equal share of the marbles. This would be easy if all the marbles had the same value, because then they could just split the collection in half. But unfortunately, some of the marbles are larger, or more beautiful than others. So, Marsha and Bill start by assigning a value, a natural number between one and six, to each marble. Now they want to divide the marbles so that each of them gets the same total value. Unfortunately, they realize that it might be impossible to divide the marbles in this way (even if the total value of all marbles is even). For example, if there are one marble of value 1, one of value 3 and two of value 4, then they cannot be split into sets of equal value. So, they ask you to write a program that checks whether there is a fair partition of the marbles.

Input

Each line in the input file describes one collection of marbles to be divided. The lines contain six non-negative integers n1 , . . . , n6 , where ni is the number of marbles of value i. So, the example from above would be described by the input-line “1 0 1 2 0 0”. The maximum total number of marbles will be 20000. The last line of the input file will be “0 0 0 0 0 0”; do not process this line.

Output

For each collection, output “Collection #k:”, where k is the number of the test case, and then either “Can be divided.” or “Can’t be divided.”. Output a blank line after each test case.

Sample Input

1
2
3
1 0 1 2 0 0 
1 0 0 0 1 1
0 0 0 0 0 0

Sample Output

1
2
3
4
5
Collection #1:
Can't be divided.

Collection #2:
Can be divided.
阅读全文 »

Poj2386 Lake Counting

发表于 2018-09-16 | 更新于: 2019-02-16 | 分类于 Algorithm , Search , Depth First Search |
字数统计: 442 | 阅读时长 ≈ 2

Description

Due to recent rains, water has pooled in various places in Farmer John’s field, which is represented by a rectangle of N x M (1 <= N <= 100; 1 <= M <= 100) squares. Each square contains either water (‘W’) or dry land (‘.’). Farmer John would like to figure out how many ponds have formed in his field. A pond is a connected set of squares with water in them, where a square is considered adjacent to all eight of its neighbors. Given a diagram of Farmer John’s field, determine how many ponds he has.

Input

* Line 1: Two space-separated integers: N and M * Lines 2..N+1: M characters per line representing one row of Farmer John’s field. Each character is either ‘W’ or ‘.’. The characters do not have spaces between them.

Output

* Line 1: The number of ponds in Farmer John’s field.

Sample Input

1
2
3
4
5
6
7
8
9
10
11
10 12
W........WW.
.WWW.....WWW
....WW...WW.
.........WW.
.........W..
..W......W..
.W.W.....WW.
W.W.W.....W.
.W.W......W.
..W.......W.

Sample Output

1
3
阅读全文 »

Hdu1241 Oil Deposits

发表于 2018-09-16 | 更新于: 2019-02-16 | 分类于 Algorithm , Search , Depth First Search |
字数统计: 505 | 阅读时长 ≈ 2

Description

The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular region of land at a time, and creates a grid that divides the land into numerous square plots. It then analyzes each plot separately, using sensing equipment to determine whether or not the plot contains oil. A plot containing oil is called a pocket. If two pockets are adjacent, then they are part of the same oil deposit. Oil deposits can be quite large and may contain numerous pockets. Your job is to determine how many different oil deposits are contained in a grid.

Input

The input file contains one or more grids. Each grid begins with a line containing m and n, the number of rows and columns in the grid, separated by a single space. If m = 0 it signals the end of the input; otherwise 1 <= m <= 100 and 1 <= n <= 100. Following this are m lines of n characters each (not counting the end-of-line characters). Each character corresponds to one plot, and is either ‘*’, representing the absence of oil, or ‘@’, representing an oil pocket.

Output

For each grid, output the number of distinct oil deposits. Two different pockets are part of the same oil deposit if they are adjacent horizontally, vertically, or diagonally. An oil deposit will not contain more than 100 pockets.

Sample Input

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
1 1
*
3 5
*@*@*
**@**
*@*@*
1 8
@@****@*
5 5
****@
*@@*@
*@**@
@@@*@
@@**@
0 0

Sample Output

1
2
3
4
0
1
2
2
阅读全文 »
1…67
Einsturing

Einsturing

Einsturing菜鸡个人网站,写一些菜鸡东西,大家见笑

64 日志
26 分类
25 标签
GitHub BiliBili
Links
  • XLor
  • louduan
  • LTF
  • Banana
0%
© 2018 — 2019 Einsturing
主题 — NexT.Gemini v5.1.4
访问人数 人 总访问量 次