摘要: 计算方程解的个数很巧妙的hash ,主要是要注意到a,b,c,d已经x的大小范围View Code #include <iostream>#include <algorithm>using namespace std;int hash1[3000005];int main(){ int a, b, c, d, x1, x2, x3, x4, ans; while (~scanf ("%d%d%d%d", &a, &b, &c, &d)) { if (a > 0 && b > 0 && 阅读全文
posted @ 2012-02-22 22:57 枕边梦 阅读(193) 评论(0) 推荐(0)
摘要: 比较基础的并查集,求集合所含元素的个数,中间用字典树给出现过的名字标号View Code #include<iostream>#include<algorithm>#include<string>#define MAXN 100000+10using namespace std;int f[MAXN],r[MAXN],n,num;typedef struct node{ int cnt; struct node *next[52];}*tree,Trie;tree root; inline int GetNum(char *t)//用字典树对字符串编号{ t 阅读全文
posted @ 2012-02-22 20:32 枕边梦 阅读(242) 评论(0) 推荐(0)
摘要: 简单的DFS,将所有未填的位置依次保存起来,之后,对每一个未填的位置依次枚举,往下搜即可;;本来想用DLX的做的,hdu3111是过了,可是原先那个模板在这道题里就是超时,不解啊,换一个模板就过了、DFS版#include<stdio.h>struct point{ int x, y;} p[81];int num, flag, map[10][10];int judge(int n, int k){ int i, j, x, y; for(i = 0; i < 9; i++) { if(i != p[n].y && map[p[n].x][i] == k.. 阅读全文
posted @ 2012-02-22 19:34 枕边梦 阅读(891) 评论(0) 推荐(0)
摘要: 精确覆盖: 首先选择当前要覆盖的列(含1最少的列),将该列和能够覆盖到该列的行全部去掉,再枚举添加的方法。枚举某一行r,假设它是解集中的一个,那么该行所能覆盖到的所有列都不必再搜,所以删除该行覆盖到的所有列,又由于去掉的列相当于有解,所以能够覆盖到这些列的行也不用再搜,删之。View Code /*DLX解决9*9的数独问题,转化为729*324的精确覆盖问题行:一共9 * 9 * 9 == 729行。一共9 * 9小格,每一格有9种可能性(1 - 9),每一种可能都对应着一行。列:一共(9 + 9 + 9) * 9 + 81 == 324 种前面三个9分别代表着9行9列和9小块,乘以9的意思 阅读全文
posted @ 2012-02-22 19:21 枕边梦 阅读(1253) 评论(0) 推荐(0)