QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#795617#6534. Peg SolitaireRUOHUIRE 0ms0kbC++203.0kb2024-11-30 22:11:462024-11-30 22:11:47

Judging History

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

  • [2024-11-30 22:11:47]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-11-30 22:11:46]
  • 提交

answer

#include "bits/stdc++.h"
#define int long long
using namespace std;
const int N = 2e6 + 10;
int n, m, k;
int a[10][10],num,ans;
struct node
{
    int x, y; /* data */
} q[N];
bool cmp(node w, node v)
{
    return w.x < v.x;
}
inline int dfs()
{
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if(a[i][j]&&i+1<=n&&a[i+1][j]) 
            {
               if(i+2<=n&&!a[i+2][j])
               {
                   a[i][j] = a[i + 1][j] = 0;
                   a[i+2][j] = 1;
                   num--;
                   ans=min(ans,num);
                   dfs();
                   a[i][j] = a[i + 1][j] = 1;
                   a[i + 2][j] = 0;
                   num++;
               }
               if (i-1>=1 && !a[i -1][j])
               {
                   a[i][j] = a[i + 1][j] = 0;
                   a[i -1][j] = 1;
                   num--;
                   ans = min(ans, num);
                   dfs();
                   a[i][j] = a[i + 1][j] = 1;
                   a[i -1][j] = 0;
                   num++;
               }
            }
            if(a[i][j]&&j+1<=m&&a[i][j+1])
            {
                if(j+2<=m&&!a[i][j+2])
                {
                    a[i][j]=a[i][j+1]=0;
                    a[i][j+2]=1;
                    num--;
                    ans = min(ans, num);
                    dfs();
                    a[i][j] = a[i][j + 1] = 1;
                    a[i][j + 2] = 0;
                    num++;
                }
                if(j-1>=1&&!a[i][j-1])
                {
                    a[i][j] = a[i][j + 1] = 0;
                    a[i][j -1] = 1;
                    num--;
                    ans = min(ans, num);
                    dfs();
                    a[i][j] = a[i][j + 1] = 1;
                    a[i][j -1] = 0;
                    num++;
                }
            }
        }
    }
}
void solve()
{
    //cin >> n;
    for(int i=0;i<10;i++)
       for(int j=0;j<10;j++) a[i][j]=0;
    cin >> n >> m >> k;
    ans=k;
    num=k;
    for (int i = 1; i <= k; i++)
    {
        int x, y;
        cin >> x >> y;
        a[x][y] = 1;
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            if (a[i][j])
                dfs();
        }
    }
    cout<<ans<<endl;
    // for (int i = 1; i <= n; i++)
    // {
    //     cin >> a[i];
    // }
    // cin >> m;
    // int h = 1, t = 0;
    // for (int i = 1; i <= m; i++)
    // {
    //     cin >> q[i].x >> q[i].y;
    // }
    // sort(q + 1, q + m + 1, cmp);
    // for (int i = 1; i <= m; i++)
    // {
    //     int l = q[i].x, r = q[i].y;
    // }
}
signed main()
{

    ios::sync_with_stdio(false);
    cin.tie(0);

    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);

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

詳細信息

Test #1:

score: 0
Runtime Error

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:


result: