QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#703397#6534. Peg Solitairelllei#AC ✓1ms3868kbC++201.3kb2024-11-02 17:42:512024-11-02 17:43:08

Judging History

你现在查看的是最新测评结果

  • [2024-11-02 17:43:08]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:3868kb
  • [2024-11-02 17:42:51]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int T;
int n,m,k;
int mp[10][10];
vector<pair<int,int> >v;
int ans=6;
void dfs(vector<pair<int,int> >cur)
{
    ans=min(ans,(int)cur.size());
    vector<pair<int,int> >nxt;
    for(int i=0;i<cur.size();i++)
    for(int j=0;j<cur.size();j++)
    if(i!=j&&abs(cur[i].first-cur[j].first)+abs(cur[i].second-cur[j].second)==1)
    {
        int nx=cur[j].first*2-cur[i].first;
        int ny=cur[j].second*2-cur[i].second;
        if(nx<1||nx>n||ny<1||ny>m)continue;
        if(mp[nx][ny])continue;
        mp[nx][ny]=1;
        mp[cur[i].first][cur[i].second]=0;
        mp[cur[j].first][cur[j].second]=0;
        nxt.clear();
        for(int k=0;k<cur.size();k++)if(k!=j&&k!=i)nxt.push_back(cur[k]);
        nxt.push_back({nx,ny});
        dfs(nxt);
        mp[nx][ny]=0;
        mp[cur[i].first][cur[i].second]=1;
        mp[cur[j].first][cur[j].second]=1;
    }
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin>>T;
    while(T--)
    {
        memset(mp,0,sizeof(mp));
        v.clear();
        cin>>n>>m>>k;
        for(int i=1;i<=k;i++)
        {
            int x,y;
            cin>>x>>y;
            mp[x][y]=1;
            v.push_back({x,y});
        }
        ans=v.size();
        dfs(v);
        cout<<ans<<'\n';
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3644kb

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: 0ms
memory: 3688kb

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: 0ms
memory: 3868kb

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: 0ms
memory: 3640kb

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
1 1
2 1
3 4
1 5
2 2
3 3
2 5 2
2 5
2 1
5 4 6
1 3
4 3
2 2
1 2
3 3
2 3
2 3 3
2 3
1 1
1 3
1 1 1
1 1
1 1 1
1 1
1 1 1
1 1
6 4 5
2 1
6 2
3 2
1 2
4 2
5...

output:

2
1
2
2
1
2
3
2
2
3
1
1
1
3
2
2
2
3
2
1

result:

ok 20 numbers

Test #5:

score: 0
Accepted
time: 1ms
memory: 3636kb

input:

20
6 6 6
2 4
3 4
3 3
4 3
4 2
5 2
6 6 6
2 4
3 4
3 3
4 3
4 2
5 2
6 6 6
2 4
3 4
3 3
4 3
4 2
5 2
6 6 6
2 4
3 4
3 3
4 3
4 2
5 2
6 6 6
2 4
3 4
3 3
4 3
4 2
5 2
6 6 6
2 4
3 4
3 3
4 3
4 2
5 2
6 6 6
2 4
3 4
3 3
4 3
4 2
5 2
6 6 6
2 4
3 4
3 3
4 3
4 2
5 2
6 6 6
2 4
3 4
3 3
4 3
4 2
5 2
6 6 6
2 4
3 4
3 3
4 3
4 2
5...

output:

2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2

result:

ok 20 numbers