QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#103377 | #4376. Dragon slayer | sine_and_cosine# | AC ✓ | 446ms | 3400kb | C++17 | 2.9kb | 2023-05-05 15:26:30 | 2023-05-05 15:26:33 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define endl '\n'
#define eb emplace_back
#define INF (int)(1e18)
#define pii pair<int, int>
const int MOD = 1e9 + 7;
int fast(int x, int n) {
int ret = 1;
while (n) {
if (n & 1) ret = ret * x % MOD;
x = x * x % MOD;
n >>= 1;
}
return ret;
}
int arr[33][33];
int vis[33][33];
int dr[4] = {1, 0, -1, 0};
int dc[4] = {0, 1, 0, -1};
void run() {
memset(arr, 0, sizeof arr);
int n, m, K;
cin >> n >> m >> K;
n *= 2;
m *= 2;
pii st, ed;
cin >> st.first >> st.second >> ed.first >> ed.second;
st.first *= 2;
st.first++;
st.second *= 2;
st.second++;
ed.first *= 2;
ed.first++;
ed.second *= 2;
ed.second++;
vector<pair<pii, pii> > all;
for (int i = 0; i < K; i++) {
pii fst, sec;
cin >> fst.first >> fst.second >> sec.first >> sec.second;
fst.first *= 2;
fst.second *= 2;
sec.first *= 2;
sec.second *= 2;
all.eb(fst, sec);
}
int ans = K;
for (int mask = 0; mask < (1LL << K); mask++) {
memset(arr, 0, sizeof arr);
for (int i = 0; i < K; i++) {
if (mask & (1LL << i)) {
pii fst = all[i].first, sec = all[i].second;
if (fst.first == sec.first) {
for (int j = min(fst.second, sec.second); j <= max(fst.second, sec.second); j++) {
arr[fst.first][j] = 1;
}
} else {
for (int j = min(fst.first, sec.first); j <= max(fst.first, sec.first); j++) {
arr[j][fst.second] = 1;
}
}
}
}
memset(vis, 0, sizeof vis);
queue<pii> q;
q.push(st);
vis[(int)st.first][(int)st.second] = 1;
int flag = 0;
while (!q.empty()) {
pii now = q.front();
// cout << "???-> " << now.first << ' ' << now.second << endl;
q.pop();
if (now == ed) {
flag = 1;
break;
}
for (int k = 0; k < 4; k++) {
pii nx = pii(now.first + dr[k], now.second + dc[k]);
if (nx.first >= 0 && nx.first <= n && nx.second >= 0 && nx.second <= m && !vis[nx.first][nx.second] && !arr[nx.first][nx.second]) {
vis[nx.first][nx.second] = 1;
q.push(nx);
}
}
}
if (flag) {
ans = min(ans, K - __builtin_popcount(mask));
// cout << "??-> " << mask << endl;
}
}
cout << ans << endl;
return;
}
signed main() {
ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
int T = 1;
cin >> T;
while (T--) {
run();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 446ms
memory: 3400kb
input:
10 4 4 4 0 2 3 3 0 2 4 2 1 3 1 0 2 4 2 1 3 1 3 4 3 2 2 0 0 2 1 0 1 3 1 1 0 1 2 3 2 2 0 0 2 1 2 1 2 2 1 0 1 1 15 15 15 3 12 4 1 8 0 8 15 1 11 15 11 1 1 1 15 3 1 3 15 0 10 14 10 14 1 14 14 8 1 8 15 1 5 14 5 0 15 14 15 0 4 14 4 0 2 15 2 11 0 11 15 4 1 4 15 1 11 15 11 1 12 14 12 15 15 15 8 5 14 0 0 12 1...
output:
1 2 0 5 3 5 1 4 1 0
result:
ok 10 lines