Tile和象限

Google地图Tile加载机制
Google 暂时用了4个服务器来进行负载均衡,分别是mt0, mt1, mt2 和 mt3.
 
地图是用Tile来显示的,每个Tile是256×256的png图片. Tile的个数根据Zoom Factor 实现变化,这里有一个公式:
如果Zoom Factor是z,那么水平和垂直的Tile总数是2^(17-z)。
 
Tile被分成4个象限,顺时针依次是:q,r,s和t; 要想看哪个象限,就把这个字符附到t的后面就可以了。例如:t=tq,代表左上的象限。依次类推.....
 
4台服务器,4个象限,似乎每台服务器负责一个象限,然后将4个象限拼在一起。
修改下面代码,使输出结果格式与预期相同:#include <iostream> #include <vector> #include <iomanip> using namespace std; // 全局变量:棋盘、当前使用的骨牌编号、特殊方格坐标 vector<vector<int>> board; int tile = 1; // 骨牌编号,从1开始 int specialRow, specialCol; // 分治法进行棋盘覆盖 void chessCover(int topRow, int topCol, int size, int specialRow, int specialCol) { if (size == 1) return; // 1x1棋盘无需覆盖 int half = size / 2; int tileNum = tile++; // 当前使用的骨牌编号 // 判断特殊方格在哪个象限 bool specialInTopLeft = (specialRow < topRow + half && specialCol < topCol + half); bool specialInTopRight = (specialRow < topRow + half && specialCol >= topCol + half); bool specialInBottomLeft = (specialRow >= topRow + half && specialCol < topCol + half); // 默认不在第四象限即为在右下 bool specialInBottomRight = !specialInTopLeft && !specialInTopRight && !specialInBottomLeft; // 根据特殊方格所在象限,放置中间的L型骨牌 if (!specialInTopLeft) { board[topRow + half - 1][topCol + half - 1] = tileNum; } if (!specialInTopRight) { board[topRow + half - 1][topCol + half] = tileNum; } if (!specialInBottomLeft) { board[topRow + half][topCol + half - 1] = tileNum; } if (!specialInBottomRight) { board[topRow + half][topCol + half] = tileNum; } // 递归处理四个子棋盘 if (specialInTopLeft) { chessCover(topRow, topCol, half, specialRow, specialCol); } else { chessCover(topRow, topCol, half, topRow + half - 1, topCol + half - 1); } if (specialInTopRight) { chessCover(topRow, topCol + half, half, specialRow, specialCol); } else { chessCover(topRow, topCol + half, half, topRow + half - 1, topCol + half); } if (specialInBottomLeft) { chessCover(topRow + half, topCol, half, specialRow, specialCol); } else { chessCover(topRow + half, topCol, half, topRow + half, topCol + half - 1); } if (specialInBottomRight) { chessCover(topRow + half, topCol + half, half, specialRow, specialCol); } else { chessCover(topRow + half, topCol + half, half, topRow + half, topCol + half); } } int main() { int n; cin >> n; cin >> specialRow >> specialCol; // 初始化棋盘 board.assign(n, vector<int>(n, 0)); board[specialRow][specialCol] = 0; // 特殊格子标记为0 // 开始分治覆盖 chessCover(0, 0, n, specialRow, specialCol); // 输出结果 for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { cout << setw(4) << board[i][j]; } cout << endl; } return 0; }
最新发布
12-01
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值