摘要:
题意:给出正方形棋盘边长n(最大300),要求输出一种摆放n皇后不冲突的方案。分析:数据范围较大,只能用构造的方法,不能用搜索。下面用一个数列表示一种方案,第i个数表示棋盘第i行上的皇后所在的列号n皇后问题构造法:一、当n mod 6 != 2 且 n mod 6 != 3时,有一个解为:2,4,6,8,...,n,1,3,5,7,...,n-1 (n为偶数)2,4,6,8,...,n-1,1,3,5,7,...,n (n为奇数)(上面序列第i个数为ai,表示在第i行ai列放一个皇后;...省略的序列中,相邻两数以2递增。下同)二、当n mod 6 == 2 或 n mod 6 == ... 阅读全文
posted @ 2011-07-12 15:41
undefined2024
阅读(709)
评论(0)
推荐(0)
摘要:
题意:给出若干个正方形的边长,和平面直角坐标系中的两条起点在原点的射线(射线上的点表示射线),两条射线在第一象限。要求用这些正方形和这两条射线围成一块封闭的面积,求最大面积。分析:把正方形对角线连成一条直线,排成一个斜率为-1的直线。这样才能保证面积最大。所以现在的问题变为,已知两条射线的方向,以及三角形第三条边的斜率(斜率为-1)和长度(正方形边长和×sqrt(2))求三角形的面积(当然最终结果是三角形面积减去正方形面积的一半)设有a,b两向量,方向是两射线方向,设ka*a为三角形的一条射线上的边,kb×b为三角形另一条射线上的边。(即将两向量适当延长)延长后两向量的差即 阅读全文
posted @ 2011-07-12 11:29
undefined2024
阅读(330)
评论(0)
推荐(0)
摘要:
bfsView Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;#define maxn 55struct Point{ int x, y;}q[maxn * maxn];int n, m, ans;int map[maxn][maxn];bool vis[maxn][maxn];int dir[4][2] ={{ 0, -1 },{ -1, 0 },{ 0, 1 },{ 1, 0 } };bool o 阅读全文
posted @ 2011-07-12 09:41
undefined2024
阅读(239)
评论(0)
推荐(0)
摘要:
简单题View Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>using namespace std;char st[100];int main(){ //freopen("t.txt", "r", stdin); while (scanf("%s", st)) { if (strcmp(st, "#") == 阅读全文
posted @ 2011-07-12 09:07
undefined2024
阅读(286)
评论(0)
推荐(0)
摘要:
dfsView Code #include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;#define maxn 25int n, m;int f[maxn], s[maxn];int ans;void dfs(int cow, int sum){ if (ans == 0) return; if (s[cow] + sum < m) return; if (sum >= m) { ans = min(ans, s 阅读全文
posted @ 2011-07-12 08:32
undefined2024
阅读(173)
评论(0)
推荐(0)