程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> UVA 687 - Lattice Practices(暴力枚舉+位運算)

UVA 687 - Lattice Practices(暴力枚舉+位運算)

編輯:C++入門知識

Lattice Practices

Once upon a time, there was a king who loved beautiful costumes very much. The king had a special cocoon bed to make excellent cloth of silk. The cocoon bed had 16 small square rooms, forming a 4$\times$4 lattice, for 16 silkworms. The cocoon bed can be depicted as follows:

\

The cocoon bed can be divided into 10 rectangular boards, each of which has 5 slits:<喎?http://www.Bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+PC9wPgo8aW1nIHNyYz0="http://www.Bkjia.com/uploadfile/Collfiles/20131231/20131231094708216.gif" alt="\">

Note that, except for the slit depth, there is no difference between the left side and the right side of the board (or, between the front and the back); thus, we cannot distinguish a symmetric board from its rotated image as is shown in the following:

\

Slits have two kinds of depth, either shallow or deep. The cocoon bed should be constructed by fitting five of the boards vertically and the others horizontally, matching a shallow slit with a deep slit.


Your job is to write a program that calculates the number of possible configurations to make the lattice. You may assume that there is no pair of identical boards. Notice that we are interested in the number of essentially different configurations and therefore you should not count mirror image configurations and rotated configurations separately as different configurations.


The following is an example of mirror image and rotated configurations, showing vertical and horizontal boards seperately, where shallow and deep slits are denoted by `1" and `0' respectively.

\

Notice that a rotation may exchange positions of a vertical board and a horizontal board.

Input

The input consists of multiple data sets, each in a line. A data set gives the patterns of slits of 10 boards used to construct the lattice. The format of a data set is as follows:

xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx

Each x is either `0' or `1'. `0' means a deep slit, and `1' a shallow slit. A block of five slit descriptions corresponds to a board. There are 10 blocks of slit descriptions in a line. Two adjacent blocks are separated by a space.


For example, the first data set in the Sample Input means the set of the following 10 boards:

\

The end of the input is indicated by a line consisting solely of three characters ``END"'.

Output

For each data set, the number of possible configurations to make the lattice from the given 10 boards should be output, each in a separate line.

Sample Input

10000 01000 00100 11000 01100 11111 01110 11100 10110 11110
10101 01000 00000 11001 01100 11101 01110 11100 10110 11010
END

Sample Output

40
6

題意:給10塊床坂,求可以拼出的種數,旋轉對稱算一種。

思路:每一塊可以用一個2進制數表示,並且拼圖是不重復的。所以只要開一個32的數組就能存放拼圖了。暴力枚舉。枚舉5塊正放逆放,然後另外5快去判斷能不能組成,一開始想總情況直接除以8,結果一直WA,後面改成用SET保存下找到過的方法的對應的8種方法,就過了。。哎,寫得很搓,卡了兩天了。。

代碼:

#include 
#include 
#include 
#include 
#include 
using namespace std;

const int zhuan[25] = {20, 15, 10, 5, 0, 21, 16, 11, 6, 1, 22 ,17, 12, 7, 2, 23, 18, 13, 8, 3, 24, 19, 14, 9, 4};
const int dui[25] = {4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 14, 13, 12, 11, 10, 19, 18, 17, 16, 15, 24, 23, 22, 21, 20};
const int N = 20;

char str[N], sb[30], sbb[30];
int way[N], ans, save[N], saven, v[32], z[32];
set state;
void zh(char *a) {
	char save[30];
	for (int i = 0; i < 25; i ++)
		save[i] = a[zhuan[i]];
	save[25] = '\0';
	strcpy(a, save);
}

void dc(char *a) {
	char save[30];
	for (int i = 0; i < 25; i ++)
		save[i] = a[dui[i]];
	save[25] = '\0';
	strcpy(a, save);
}

int hash(char *s) {
	int sum = 0;
	for (int i = 0; i < 5; i ++)
		if (s[i] == '1') sum = sum * 2 + 1;
		else sum *= 2;
	return sum;
}

void init() {
	state.clear();
	memset(sb, 0, sizeof(sb));
	memset(sbb, 0, sizeof(sbb));
	memset(v, 0, sizeof(v));
	v[hash(str)]++; v[z[hash(str)]]++;
	for (int i = 1; i < 10; i++) {
		scanf("%s", str);
		v[hash(str)]++; v[z[hash(str)]]++;
	}
}

bool find(int s) {
	if (v[s]) {
		v[s]--; v[z[s]]--;
		save[saven++] = s;
		return true;
	}
	return false;
}

bool judge() {
	for (int i = 4; i >= 0; i --) {
		int s = 0;
		for (int j = 0; j < 5; j ++) {
			if ((way[j] & (1<= 0; i --) {
		for (int j = 0; j < 5; j ++) {
			if ((way[j] & (1<= 0; i--) {
		if (num >= (1<



  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved