2013年3月15日

zoj 2412 水田灌溉,求连通分支个数

摘要: 次题的关键是把稻田的中心点抽象成图中的点,两中心点有水管相连表示两点连通,这样,此题就转化成了求图的连通分支数目View Code 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 using namespace std; 5 char grid[52][52]; 6 char map[52][52]; 7 int m,n; 8 int dir[4][2] = {{-1,0},{0,1},{0,-1},{1,0}}; // 上,右,左,下 9 //编号分别为 0,1,2,310 阅读全文

posted @ 2013-03-15 17:14 allh123 阅读(222) 评论(0) 推荐(0) 编辑

z0j1008Gnome Tetravex

摘要: 该题是找满足条件的摆法,直接DFS会超时,关键是压缩存储,同一种正方形只存一次,再DFS,然后搜到一种成功的就要退出,不要把所有可能的摆法都搜完,不然也会超时。初始化种类数不要忘记。View Code 1 #include <cstdio> 2 #include <cstring> 3 bool flag ; //成功标志 4 int n,kinds; //正方形的个数为n*n,种类为kinds 5 struct square 6 { 7 int top,bottom,left,right; 8 int num; //该类正方行的个数 9 } rect[26];//记录 阅读全文

posted @ 2013-03-15 16:57 allh123 阅读(157) 评论(0) 推荐(0) 编辑

导航