QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#473582#6534. Peg Solitairemufeng12AC ✓1ms3856kbC++233.4kb2024-07-12 10:40:282024-07-12 10:40:29

Judging History

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

  • [2024-07-12 10:40:29]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:3856kb
  • [2024-07-12 10:40:28]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define inf 0x3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define maxint INT32_MAX
#define minint INT32_MIN
#define maxll INT64_MAX
#define minll INT64_MIN
#define mod  998244353
#define nc() (p1==p2 && (p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++)
#pragma GCC optimize(2)
void write(int x);
ll c[120][120];
char *p1,*p2,buf[100000];
int read();
const int N=1e5+10;
int fact[N],infact[N];
int n,m,k;
vector<vector<int>> mp(7,vector<int>(7,0));
int ans=1000;
void dfs(int k){
    if(k==1) {ans=min(ans,k);return;}
    for(int i=1;i<=n;i++){    
        for(int j=1;j<=m;j++){
            if(mp[i][j]){
                if(i+1<=n&&mp[i+1][j]){
                    if(i+2<=n&&!mp[i+2][j]){
                        mp[i+2][j]=1;
                        mp[i][j]=0;
                        mp[i+1][j]=0;
                        dfs(k-1);
                        ans=min(ans,k);
                        mp[i+2][j]=0;
                        mp[i][j]=1;
                        mp[i+1][j]=1; 
                    }
                }
                if(i-1>0&&mp[i-1][j]){
                    if(i-2>0&&!mp[i-2][j]){
                        mp[i-2][j]=1;
                        mp[i][j]=0;
                        mp[i-1][j]=0;
                        dfs(k-1);
                        ans=min(ans,k);
                        mp[i-2][j]=0;
                        mp[i][j]=1;
                        mp[i-1][j]=1;
                    }
                }
                if(j+1<=m&&mp[i][j+1]){
                    if(j+2<=m&&!mp[i][j+2]){
                        mp[i][j+2]=1;
                        mp[i][j]=0;
                        mp[i][j+1]=0;
                        dfs(k-1);
                        ans=min(ans,k);
                        mp[i][j+2]=0;
                        mp[i][j]=1;
                        mp[i][j+1]=1;
                    }
                }
                if(j-1>0&&mp[i][j-1]){
                    if(j-2>0&&!mp[i][j-2]){
                        mp[i][j-2]=1;
                        mp[i][j]=0;
                        mp[i][j-1]=0;
                        dfs(k-1);
                        ans=min(ans,k);
                        mp[i][j-2]=0;
                        mp[i][j]=1;
                        mp[i][j-1]=1;

                    }
                }
            }
        }
    }
    ans=min(ans,k);
}
void solve(){
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++)
        mp[i].assign(m+1,0);
    for(int i=1;i<=k;i++){
        int x,y;
        cin>>x>>y;
        mp[x][y]=1;
    }
    dfs(k);
    cout<<ans<<endl;
    ans=1000;     
}

int main() {
    int t=1;
    cin>>t;
    while(t--) solve();
    return 0;
}



void write(int x)
{
    if(x<0)
        putchar('-'),x=-x;
    if(x>9)
        write(x/10);
    putchar(x%10+'0');
    return;
}
int read()
{
    int x=0,f=1;
    char ch=nc();
    while(ch<48||ch>57)
    {
        if(ch=='-')
            f=-1;
        ch=nc();
    }
    while(ch>=48&&ch<=57)
        x=x*10+ch-48,ch=nc();
   	return x*f;
}

// ll ksm(ll a,ll b,ll mod){
//     ll ans=1;
//     a%=mod;
//     while(b>0){
//         if(b&1) ans=ans*a%mod;
//         a=a*a%mod;
//         b>>=1;
//     }
//     return ans;
// }

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3608kb

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: 3776kb

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: 3856kb

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: 3544kb

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: 3492kb

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