棋盘覆盖问题
2015-06-15 20:48
369 查看
#include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> #include <algorithm> #include <ctype.h> #include <iostream> #include <set> #include <map> #include <queue> #include <stack> #include <assert.h> #include <time.h> #include <sstream> typedef long long LL; const int INF = 500000001; const double EPS = 1e-9; const double PI = acos(-1.0); using namespace std; int g[100][100]; int cur, n; void gao(int x, int y, int tx, int ty, int len) { if(len == 1) return ; int t = len / 2; int tmpx = x + t; int tmpy = y + t; int k = cur; cur++; if(tx < tmpx && ty < tmpy) { gao(x, y, tx, ty, t); } else { g[tmpx - 1][tmpy - 1] = k; gao(x, y, tmpx - 1, tmpy - 1, t); } if(tx < tmpx && ty >= tmpy) { gao(x, tmpy, tx, ty, t); } else { g[tmpx - 1][tmpy] = k; gao(x, tmpy, tmpx - 1, tmpy, t); } if(tx >= tmpx && ty < tmpy) { gao(tmpx, y, tx, ty, t); } else { g[tmpx][tmpy - 1] = k; gao(tmpx, y, tmpx, tmpy - 1, t); } if(tx >= tmpx && ty >= tmpy) { gao(tmpx, tmpy, tx, ty, t); } else { g[tmpx][tmpy] = k; gao(tmpx, tmpy, tmpx, tmpy, t); } } int main() { #ifdef _Te3st freopen("test0.in", "r", stdin); freopen("test0.out", "w", stdout); srand(time(NULL)); #endif int T, x, y; int c = 1; scanf("%d", &T); while(T--) { printf("CASE:%d\n", c++); cur = 1; scanf("%d", &n); scanf("%d %d", &x, &y); g[x][y] = 0; gao(0, 0, x, y, n); for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { printf(j?"\t%d":"%d", g[i][j]); } puts(""); } } return 0; }
相关文章推荐
- 《算法竞赛入门经典》解题索引
- Uva 101:The Blocks Problem(木块问题)
- 《算法竞赛入门经典》上机练习——第二章
- 算法竞赛入门经典-第一章源代码
- 算法竞赛入门经典-第二章源代码
- 算法竞赛入门经典-第三章源代码
- 算法竞赛入门经典-第四章源代码
- 算法竞赛入门经典-第五章源代码
- 算法竞赛入门经典第二章笔记
- 算法竞赛入门经典第三章笔记
- 算法竞赛入门经典第四章笔记
- UVa 10055 Hashmat the brave warrior(勇士)
- UVa 10071 Back to High School Physics(重温高中物理)
- UVa 10300 Ecological Premium(生态奖金)
- UVa 458 The Decoder(解码器)
- UVa 494 Kindergarten Counting Game(幼儿园数数游戏)
- UVa 414 Machined Surfaces(机器加工的表面)
- UVa 490 Rotating Sentences(旋转句子)
- UVa 445 Marvelous Mazes(非凡的迷宫)
- UVa 488 Triangle Wave(三角波)