vector修改前后,iterator可能发生不可预知的变化,必须谨慎! //pku3620 Avoid The Lakes #include <cstdio> #include <vector> using namespace std; typedef long INT32; const INT32 MAX_N = 100; enum STAT { ST_DRY=0, ST_SUBMERGE, ST_TRAVELED }; typedef struct tagPOS { INT32 x; INT32 y; tagPOS(INT32 _x, INT32 _y) { x=_x; y=_y; } inline tagPOS operator+ (const tagPOS& in) const { return tagPOS(x+in.x, y+in.y); } } POS; vector<POS> vSubmergeCells, vQueue; STAT grid[MAX_N+2][MAX_N+2]; POS aDirection[4] = {POS(0,1), POS(1,0), POS(0,-1), POS(-1,0)}; int main() { INT32 iN, iM, iK; INT32 i; INT32 iMaxSize = 0; scanf("%ld %ld %ld", &iN, &iM, &iK); for (i=0; i<iK; i++) { INT32 x, y; scanf("%ld %ld", &x, &y); vSubmergeCells.push_back(POS(x,y)); grid[x][y] = ST_SUBMERGE; } vector<POS>::iterator iter; for (iter=vSubmergeCells.begin(); iter!=vSubmergeCells.end(); ++iter) { const POS posStart = *iter; if (ST_SUBMERGE == grid[posStart.x][posStart.y]) { vQueue.clear(); vQueue.push_back(posStart); grid[posStart.x][posStart.y] = ST_TRAVELED; INT32 iIndex = 0; while (iIndex < vQueue.size()) { const POS posCur = vQueue[iIndex++]; INT32 dir; for (dir=0; dir<4; dir++) { POS posNew = posCur + aDirection[dir]; if (ST_SUBMERGE == grid[posNew.x][posNew.y]) { vQueue.push_back(posNew); grid[posNew.x][posNew.y] = ST_TRAVELED; } } } if (iMaxSize < vQueue.size()) iMaxSize = vQueue.size(); } } printf("%ld/n", iMaxSize); return 0; }