nginx httpgzip模块
2016-01-07 10:46
423 查看
题目描述: http://poj.org/problem?id=2676
转自: http://zhangjian110518.blog.163.com/blog/static/74991703200933092722785/
题目技巧性不强,DFS过的,用时16MS。不过写的过程中要注意从后面往前搜。
转自: http://zhangjian110518.blog.163.com/blog/static/74991703200933092722785/
题目技巧性不强,DFS过的,用时16MS。不过写的过程中要注意从后面往前搜。
/************************************************************************/ /*思路: 先从后面开始搜,也就是从第八十个开始搜 1、如果一个小的方格内已经包含了非零的数,则继续向下搜 2、如果一个小的方格内是一个零数,也就是还没有放入相应的数,则对其从零到九开始尝试 3、对每一个数的尝试,检查其合法性:在其所在的3*3方格内是否合适;在此行是否合适:在此列是否合适 4、如果经过以上条件可以的话那么这个数字就可以放在此小方格上,然后继续进行搜索。 ************************************************************************/ #include <cstdio> const int n = 9; int board[9][9]; char ch[10]; //返回当前board[x][y]中的值是否可行 bool ok(int x, int y) { // 3 * 3 for (int i = x / 3 * 3; i < x / 3 * 3 + 3; ++i) { for (int j = y / 3 * 3; j < y / 3 * 3 + 3; ++j) { if (x == i && y == j) continue; if (board[x][y] == board[i][j]) // the number has been used return false; } } int temp = board[x][y]; // check the row for (int j = 0; j < n; ++j) { if (j == y) continue; if (board[x][j] == temp) return false; } // check the column for (int i = 0; i < n; ++i) { if (i == x) continue; if (board[i][y] == temp) return false; } return true; // ok } int dfs(int location) { if (location == -1) return 1; if (board[location / n][location % n] != 0) // has number return dfs(location - 1); else { for (int i = 1; i <= n; ++i) { // try board[location / n][location % n] = i; if (ok(location / n, location % n)) { if (dfs(location - 1)) return 1; } board[location / n][location % n] = 0; } } return 0; } int main() { int nCases; scanf("%d", &nCases); while (nCases--) { for (int i = 0; i < n; ++i) { scanf("%s", ch); for (int j = 0; j < n; ++j) { board[i][j] = ch[j] - '0'; } } dfs(80); for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { printf("%d", board[i][j]); } printf("\n"); } } return 0; }
相关文章推荐
- 客户端与多服务端的TCP连接状态问题
- Httpclient远程调用WebService示例(Eclipse+httpclient)
- 图解HTTPS
- WinPcap编程之HTTP协议还原
- iOS将网络音频文件写入本地的方法
- 关于使用QTcpSocket的一些总结
- 解决github unable to access 'https://github.com/...: Failed to connect to github.com port 443
- 在CentOS7中开启httpd的mod_ssl 模块及配置
- java模拟http get和post 提交 httpclient
- TCP接受和发送程序以及长连接的处理方法
- 详解HttpURLConnection
- URL,URLConnection,HttPURLConnection的使用
- Android 封装http请求的工具类
- APP 检测网络的状态 是wifi 还是蜂窝连接
- 深入了解HTTP和Socket在实时性Web上的实践
- libevent的http服务与libjson结合
- Http 协议
- Android:3G网络是否可用
- 2016【太原网络营销师】郭文军教你如何学网络营销
- 消除SDK更新时的“https://dl-ssl.google.com refused”异常