QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#421600 | #6534. Peg Solitaire | HI_SN | AC ✓ | 1ms | 3640kb | C++20 | 1.7kb | 2024-05-25 22:05:51 | 2024-05-25 22:05:52 |
Judging History
answer
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int n, m;
void check(vector<vector<bool> >& board, int& ans, int cnt){
ans = min(ans, cnt);
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
if(board[i][j]){
if(i > 0 && i < n - 1){
//向下跳
if(board[i-1][j] && !board[i+1][j]){
board[i-1][j] = board[i][j] = false;
board[i+1][j] = true;
check(board, ans, cnt - 1);
board[i-1][j] = board[i][j] = true;
board[i+1][j] = false;
}
//向上跳
if(!board[i-1][j] && board[i+1][j]){
board[i+1][j] = board[i][j] = false;
board[i-1][j] = true;
check(board, ans, cnt - 1);
board[i+1][j] = board[i][j] = true;
board[i-1][j] = false;
}
}
if(j > 0 && j < m - 1){
//向右跳
if(board[i][j-1] && !board[i][j+1]){
board[i][j-1] = board[i][j] = false;
board[i][j+1] = true;
check(board, ans, cnt - 1);
board[i][j-1] = board[i][j] = true;
board[i][j+1] = false;
}
//向左跳
if(!board[i][j-1] && board[i][j+1]){
board[i][j+1] = board[i][j] = false;
board[i][j-1] = true;
check(board, ans, cnt - 1);
board[i][j+1] = board[i][j] = true;
board[i][j-1] = false;
}
}
}
}
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int T, k;
cin >> T;
while(T--){
cin >> n >> m >> k;
int ans = k;
vector<vector<bool> > board(n, vector<bool>(m, false));
int a, b;
for(int i = 0; i < k; i++){
cin >> a >> b;
board[a-1][b-1] = true;
}
check(board, ans, k);
cout << ans << endl;
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3576kb
input:
3 3 4 5 2 2 1 2 1 4 3 4 1 1 1 3 3 1 1 1 2 1 3 2 1 1 2 1
output:
2 3 1
result:
ok 3 number(s): "2 3 1"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3608kb
input:
20 2 1 2 1 1 2 1 5 1 3 3 1 2 1 4 1 3 3 6 1 2 2 2 1 1 2 3 3 1 3 2 4 4 4 2 3 3 1 3 2 1 2 1 1 1 1 1 5 2 6 3 2 4 1 2 1 5 2 2 2 5 1 1 3 1 1 2 1 5 1 1 5 4 6 5 4 6 4 4 2 3 4 3 1 6 6 6 3 2 4 1 3 2 1 2 2 2 2 1 1 1 5 3 4 2 2 5 1 4 3 3 2 6 5 6 5 5 6 5 2 4 2 1 3 4 1 4 2 6 5 1 6 2 1 1 4 2 3 1 3 3 5 6 2 1 3 3 1 5...
output:
2 2 3 1 1 2 1 1 3 3 2 1 3 3 2 1 3 1 2 2
result:
ok 20 numbers
Test #3:
score: 0
Accepted
time: 1ms
memory: 3640kb
input:
20 2 1 1 2 1 4 3 2 4 3 1 1 6 4 6 4 3 5 4 4 2 3 2 3 4 2 3 3 6 4 3 1 2 6 2 4 3 5 6 6 6 3 3 3 6 4 2 3 2 4 1 1 4 3 3 1 1 1 2 3 2 2 2 2 1 3 2 2 1 2 2 2 3 4 5 2 1 3 4 3 1 2 2 3 2 2 5 5 1 5 2 3 2 5 1 4 2 2 5 6 6 5 1 2 2 1 4 5 3 4 4 1 1 2 3 4 1 1 1 2 2 2 2 1 2 3 4 1 1 2 1 1 2 2 2 6 3 6 4 2 4 1 1 3 6 2 3 3 2...
output:
1 2 2 4 4 1 1 1 2 2 6 2 2 3 4 1 1 1 3 2
result:
ok 20 numbers
Test #4:
score: 0
Accepted
time: 1ms
memory: 3584kb
input:
20 1 5 3 1 2 1 3 1 1 5 6 6 5 4 2 4 4 4 4 6 2 5 3 3 5 2 4 4 1 3 1 4 2 5 2 6 3 6 3 1 5 2 3 2 4 1 4 3 3 3 5 3 5 5 2 2 2 3 1 4 3 3 2 6 1 4 3 1 5 1 1 1 4 1 3 5 6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