voidInit(){ int now = 1, cur = 0, i = 0; while (i <= 1001) { ++cur; seq[++i] = now; if (cur == now) { cur = 0; ++now; } } for (int i = 1; i <= 1000; ++i) { sum[i] = sum[i-1] + seq[i]; } }
voidWork1(){ using FastIO::getint; Init(); int x = getint(); int y = getint(); if (x > y) swap(x, y); FastIO::putint(sum[y] - sum[x-1], '\n'); } }
intgetAnswer(int x, int y){ // 获取上下左右的可扩展数量 int ret = 0; int current = 0; int ox = x; int oy = y; while (true) { ++current; ++x; if (Map[x][y] == 0) { current = 0; break; } if (Map[x][y] == 1) break; if (x == 8 && Map[x][y] == 2) { current = 0; break; } } if (current > 0) --current; ret += current; current = 0; x = ox; y = oy; while (true) { ++current; --x; if (Map[x][y] == 0) { current = 0; break; } if (Map[x][y] == 1) break; if (x == 1 && Map[x][y] == 2) { current = 0; break; } } if (current > 0) --current; ret += current; current = 0; x = ox; y = oy; while (true) { ++current; ++y; if (Map[x][y] == 0) { current = 0; break; } if (Map[x][y] == 1) break; if (y == 8 && Map[x][y] == 2) { current = 0; break; } } if (current > 0) --current; ret += current; current = 0; x = ox; y = oy; while (true) { ++current; --y; if (Map[x][y] == 0) { current = 0; break; } if (Map[x][y] == 1) break; if (y == 1 && Map[x][y] == 2) { current = 0; break; } } if (current > 0) --current; ret += current; current = 0; x = ox; y = oy; return ret; }
intgetAnswerAlt(int x, int y){ // 获取四个对角线上的可扩展数量 int ret = 0; int current = 0; int ox = x; int oy = y; while (true) { ++current; ++x; ++y; if (Map[x][y] == 0) { current = 0; break; } if (Map[x][y] == 1) break; if ((x == 8 || y == 8) && Map[x][y] == 2) { current = 0; break; } } if (current > 0) --current; ret += current; current = 0; x = ox; y = oy; while (true) { ++current; --x; --y; if (Map[x][y] == 0) { current = 0; break; } if (Map[x][y] == 1) break; if ((x == 1 || y == 1) && Map[x][y] == 2) { current = 0; break; } } if (current > 0) --current; ret += current; current = 0; x = ox; y = oy; while (true) { ++current; --x; ++y; if (Map[x][y] == 0) { current = 0; break; } if (Map[x][y] == 1) break; if ((x == 1 || y == 8) && Map[x][y] == 2) { current = 0; break; } } if (current > 0) --current; ret += current; current = 0; x = ox; y = oy; while (true) { ++current; ++x; --y; if (Map[x][y] == 0) { current = 0; break; } if (Map[x][y] == 1) break; if ((x == 8 || y == 1) && Map[x][y] == 2) { current = 0; break; } } if (current > 0) --current; ret += current; current = 0; x = ox; y = oy; return ret; }
voidSearch(){ for (int i = 1; i <= 8; ++i) { for (int j = 1; j <= 8; ++j) { if (Map[i][j] != 0) continue; ans = std::max(ans, getAnswer(i, j) + getAnswerAlt(i, j)); } } } }
voidInit(){ for (int i = 1; i <= 8; ++i) { for (int j = 1; j <= 8; ++j) { cin >> s[i][j]; } } }
intDFS(int now, int x, int y){ if (x < 1 || x > 8 || y < 1 || y > 8 || s[x][y] == '.') return -INF; if (s[x][y] == 'B') return0; return DFS(now, x + dx[now], y + dy[now]) + 1; } }
intmain(int argc, char *const argv[]){ #define HANDWER_FILE #ifndef HANDWER_FILE freopen("testdata.in", "r", stdin); freopen("testdata.out", "w", stdout); #endif usingnamespace Solution; usingnamespace FastIO; Init(); for (int i = 1; i <= 8; ++i) { for (int j = 1; j <= 8; ++j) { for (int k = 1; k <= 8; ++k) { int p = 0; if (s[i][j] == '.') { p = DFS(k, i + dx[k], j + dy[k]); if (p > 0) ans += p; // 累计答案 } } Max = std::max(Max, ans); // 更新答案 ans = 0; } } putint(Max, '\n'); return0; }
T4. 跳格子
题面
Nikola 现在已经成为一个游戏里的重要人物。这个游戏是由一行 N 个方格, N个方格 用 1 到 N 的数字表示。 Nikola 开始是在 1 号位置, 然后能够跳到其他的位置, Nikola 的第一跳必须跳到 2 号位置。随后的每一跳必须满足两个条件: 1、如果是向前跳, 必须比前面一跳远一个方格。 2、如果是向后跳, 必须和前面一跳一样远。 比如, 在第一跳之后(当在 2 号位置时), Nikola 能够跳回 1 号位置, 或者向前跳到 4号位置。 每次他跳入一个位置, Nikola 必须付费。 Nikola 的目标是从一号位置尽可能便宜地跳到 N 号位置。 写一个程序, 看看 Nikola 跳到 N 号位置时最小的花费。