Lattice animal is a set of connected sites on a lattice. Lattice animals on a square lattice are especially popular subject of study and are also known as polyominoes. Polyomino is usually represented as a set of sidewise connected squares. Polyomino…
题意 : 给定一个 w * h 的 矩阵,在矩阵中找不同n个连通块的个数(旋转,翻转,平移算作一种) 分析 : 这题的关键点有两个 ① 生成n连块并且存储起来(因为题目是多测试用例,如果每一次都重新生成必将浪费很多时间) ② 判断是否生成了重复的n连块 存储 :首先先确定用什么结构来存储n连块的信息才能更好的进行操作,n连块是多个二维坐标的集合,所以这里先定义结构体 Cell {int x, int y} 表示坐标,然后将其塞到一个集合里面set<Cell>,n连块可能有不同的多种,所以这些n…
A Puzzling Problem The goal of this problem is to write a program which will take from 1 to 5 puzzle pieces such as those shown below and arrange them, if possible, to form a square. An example set of pieces is shown here. The pieces cannot be rota…
UVA - 524 Prime Ring Problem Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Description A ring is composed of n (even number) circles as shown in diagram. Put natural numbers into each circle separately, and the sum of number…
题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&page=show_problem&problem=46 Meta-Loopless Sorts Background Sorting holds an important place in computer science. Analyzing and implementing various so…
Description You are to write a program that tries to find an optimal coloring for a given graph. Colors are applied to the nodes of the graph and the only available colors are black and white. The coloring of the graph is called optimal if a maximum…
题意 把1到n这n个数以1为首位围成一圈 输出全部满足随意相邻两数之和均为素数的全部排列 直接枚举排列看是否符合肯定会超时的 n最大为16 利用回溯法 边生成边推断 就要快非常多了 #include<cstdio> using namespace std; const int N = 50; int p[N], vis[N], a[N], n; int isPrime(int k) { for(int i = 2; i * i <= k; ++i) if(k % i == 0)…
骨牌无非两种放法,横着或竖着放,每次检查最r,c最小的没访问过的点即可.如果不能放就回溯. 最外面加一层认为已经访问过的位置,方便判断. #include<bits/stdc++.h> ; ; ; bool used[MAXB];// used Bone int pip[MAXP][MAXP];// pip 2 Bone ][]; ][]; int cnt; void dfs(int r,int c) { while(ans[r][c]) { ) { r++; c = -; } c++; }…