xxxxxxxxxxxxxxxxxxx
来源:互联网 发布:晋城网络电视台导视5 编辑:程序博客网 时间:2024/06/04 19:14
void getPos(Pos* around,int row,int column,int index){
int flag;
if (row % 2 == 0) {
flag = 0;
}else{
flag = 1;
}
// 先获取 row 行
int cursor = 0;
around[cursor].row = row;
around[cursor].column = column - index;
++cursor;
around[cursor].row = row;
around[cursor].column = column + index;
++cursor;
// row 上一行
around[cursor].row = row-1;
around[cursor].column = around[0].column + flag;
++cursor;
around[cursor].row = row-1;
around[cursor].column = around[cursor-1].column + (2*index-1);
++cursor;
int counter = 1 + flag;
if (counter == 2) {
counter = 0;
}
int lastCursor = 2;
for (int i = 2; i <= index; ++i) {
if (i == index) {
around[cursor].row = row - i;
around[cursor].column = around[lastCursor].column + counter;
++cursor;
for (int k =1; k < index + 1; ++k) {
around[cursor].row = row - i;
around[cursor].column = around[cursor-1].column +1;
++cursor;
}
break;
}else{
around[cursor].row = row - i;
around[cursor].column = around[lastCursor].column + counter;
++cursor;
around[cursor].row = row - i;
around[cursor].column = around[cursor-1].column + (2 * index - i);
++cursor;
lastCursor += 2;
}
++counter;
if (counter == 2) {
counter = 0;
}
}
/////////////////////////////////////////
/// 中间行的下一行
around[cursor].row = row + 1;
around[cursor].column = around[0].column + flag;
++cursor;
around[cursor].row = row + 1;
around[cursor].column = around[cursor-1].column + (2*index-1);
++cursor;
counter = 1 + flag;
if (counter == 2) {
counter = 0;
}
lastCursor = index * 3 + 1;
for (int i = 2; i <= index ; ++i) {
if (i == index) {
around[cursor].row = row + i;
around[cursor].column = around[lastCursor].column + counter;
++cursor;
for (int k =1; k < index + 1; ++k) {
around[cursor].row = row + i;
around[cursor].column = around[cursor-1].column +1;
++cursor;
}
break;
}else{
around[cursor].row = row + i;
around[cursor].column = around[lastCursor].column + counter;
++cursor;
around[cursor].row = row + i;
around[cursor].column = around[cursor-1].column + (2 * index - i);
++cursor;
lastCursor += 2;
}
++counter;
if (counter == 2) {
counter = 0;
}
}
}
- xxxxxxxxxxxxxxxxxxx
- 【剑指Offer面试编程题】题目1372:最大子向量和--九度OJ
- Excel表格传送至AS400时乱码问题
- UINavigationController
- GRUB4DOS资源索引帖,欢迎跟帖补充
- Redis基础之消息通知
- xxxxxxxxxxxxxxxxxxx
- skip white space and check toks
- Spring MVC框架搭建(spring4.0+hibernate4.3)
- java实现监听类
- leetcode: Majority Element
- 求s=a+aa+aaa+aaaa+aa...a的值
- iconv 中文截断问题的解决方法
- 一些安装操作记载
- Quick cocos2dx-Lua(V3.3R1)学习笔记(7) ---计时器,我是个定时吃饭睡觉的好孩子