版本比较
题解:P1526 [NOI2003] 智破连环阵
正文
增加 14 行删除 14 行
23 行未改动242526272828293031323333343536378 行未改动46474849505051525354555556575859596061626363646566666768697020 行未改动919293949595969798991001001011021031048 行未改动113114115116117117118119120121122122123124125126126127128129130130131132133133134135136137130 行未改动全部展开23 行未改动 return (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y);}
void dfs(int current_weapon, int bombs_used, vector<bool>& bomb_used) {
if (current_weapon > M) { min_bombs = min(min_bombs, bombs_used); return; }
for (int i = 0; i < n; ++i) { if (!bomb_used[i] && distanceSq(weapons[current_weapon-1], bombs[i]) <= k*k) { bomb_used[i] = true; int destroyed = current_weapon;8 行未改动
int main() { ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> M >> n >> k; weapons.resize(M); bombs.resize(n); used.resize(n, false);
for (int i = 0; i < M; ++i) { cin >> weapons[i].x >> weapons[i].y; }
for (int i = 0; i < n; ++i) { cin >> bombs[i].x >> bombs[i].y; }
vector<bool> bomb_used(n, false); dfs(1, 0, bomb_used);
cout << min_bombs << endl; return 0;}```20 行未改动}
void dfs(int current_weapon, int bombs_used, vector<bool>& bomb_used) { if (bombs_used >= min_bombs) return; // 剪枝
if (current_weapon > M) { min_bombs = min(min_bombs, bombs_used); return; }
for (int i = 0; i < n; ++i) { if (!bomb_used[i] && distanceSq(weapons[current_weapon-1], bombs[i]) <= k*k) { bomb_used[i] = true; int destroyed = current_weapon;8 行未改动
int main() { ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> M >> n >> k; weapons.resize(M); bombs.resize(n); used.resize(n, false);
for (int i = 0; i < M; ++i) { cin >> weapons[i].x >> weapons[i].y; }
for (int i = 0; i < n; ++i) { cin >> bombs[i].x >> bombs[i].y; }
vector<bool> bomb_used(n, false); dfs(1, 0, bomb_used);
cout << min_bombs << endl; return 0;}```130 行未改动全部展开