社区讨论
知道错哪里了但是不知道怎么调
P2845[USACO15DEC] Switching on the Lights S参与者 4已保存回复 3
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 3 条
- 当前快照
- 1 份
- 快照标识符
- @m4r4jzvr
- 此快照首次捕获于
- 2024/12/16 22:22 去年
- 此快照最后确认于
- 2025/11/04 12:44 4 个月前
CPP
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <map>
#include <vector>
#define mr make_pair
#define ff first
#define ss second
using namespace std;
using ll = long long;
const int N = 2e5 + 5;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int n, m, nx, ny, ans;
bool lt[102][102], vis[102][102];
vector<pair<int, int>> data[102][102];
pair<int, int> ft;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
lt[1][1] = 1;
for (int i = 1; i <= m; i++) {
int a, b, c, d;
cin >> a >> b >> c >> d;
data[a][b].push_back(mr(c, d));
}
queue<pair<int, int>> q;
pair<int, int> last;
q.push(mr(1, 1));
while (!q.empty()) {
ft = q.front();
vis[ft.first][ft.second] = 1;
q.pop();
for (auto i : data[ft.first][ft.second]) {
if (!lt[i.first][i.second]) {
lt[i.first][i.second] = 1;
// ans++;
// cout << i.first << " " << i.second << "\n";last = i;
}
last = i;
}
for (int i = 0 ; i < 4; i++) {
nx = ft.first + dx[i];
ny = ft.second + dy[i];
if (nx < 1 || ny < 1 || nx > n || ny > n || !lt[nx][ny] || vis[nx][ny]) {
continue;
}
q.push(mr(nx, ny));
}
}
for (auto i : data[last.first][last.second]) {
if (!lt[i.first][i.second]) {
lt[i.first][i.second] = 1;
// ans++;
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
// cout << lt[i][j];
if (lt[i][j]) ans++;
}
// cout << "\n";
}
cout << ans;
return 0;
}
我知道是因为是要统计开灯的数量,但是本人太菜了不会调 qwq
回复
共 3 条回复,欢迎继续交流。
正在加载回复...