OOCN分享圈's Archiver

oocn 发表于 2014-11-19 11:28

主题列表页 发帖图标旁 加 【本版搜索】代码

[attach]1354[/attach]

打开:forumdisplay.htm

找到:[code]{lang send_posts}</a></span>[/code]

下面添加:**** Hidden Message *****

Lee 发表于 2014-11-19 14:13

谢谢分享

都市圈 发表于 2014-11-20 08:46

超喜欢你这个的论坛

维达网络 发表于 2014-11-21 10:02

支持LZ分享免费东西

维达网络 发表于 2014-11-21 10:02

支持LZ分享免费东西

看代码来的 发表于 2014-11-22 14:59

谢谢分享
本文摘自:oocn资源论坛([url]http://oocn.258club.com[/url]) 详细出处请参考:[url]http://oocn.258club.com/thread-3616-1-1.html[/url]

宁灰 发表于 2014-11-26 11:58

很实用的效果 谢谢分享

王现鹏 发表于 2015-1-2 16:39

[quote]他[她]看完这篇文章说:[img]http://oocn.258club.com/attachments/month_1412/14120408334dbd1f1f6e6bfb6b.png[/img][/quote]

今天好啊 发表于 2015-3-29 02:14

:L 这都要隐藏啊……

指尖的光年 发表于 2015-6-4 00:45

[quote]他[她]看完这篇文章说:[img]http://oocn.258club.com/attachments/month_1412/141204083334b4c301ee1ebc32.png[/img][/quote]

此生此世 发表于 2015-6-20 23:56

[quote]他[她]看完这篇文章说:[img]http://oocn.258club.com/attachments/month_1412/1412040833c3cc872579ec9bec.png[/img][/quote]

发表于 2015-6-21 16:31

[quote]他[她]看完这篇文章说:[img]http://oocn.258club.com/attachments/month_1412/14120408338267b09a2bad1fe1.png[/img][/quote]

冒险家 发表于 2016-1-8 17:52

[quote]他[她]看完这篇文章说:[img]http://oocn.258club.com/attachments/month_1412/14120408338267b09a2bad1fe1.png[/img][/quote]

钟意 发表于 2016-5-1 07:18

感谢楼主分享

梅子爱阿政 发表于 2017-9-5 18:44

[quote]他[她]看完这篇文章说:[img]http://oocn.258club.com/attachments/month_1412/1412040833c3cc872579ec9bec.png[/img][/quote]

张小二 发表于 2017-12-2 01:11

[quote]他[她]看完这篇文章说:[img]http://oocn.258club.com/attachments/month_1412/1412040833f4a3160f9cd1db35.png[/img][/quote]

旧时光 发表于 2017-12-8 16:28

支持您的分享

月光 发表于 2018-1-8 11:43

支持您的分享

兰博基尼 发表于 2018-4-12 13:52

[b]回复 [url=http://www.oocn.258club.com/redirect.php?goto=findpost&pid=16367&ptid=3607]1#[/url] [i]oocn[/i] [/b]


    #include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int T,ans=20,flag;
int xx[9]={0,-2,-2,-1,-1,1,1,2,2};
int yy[9]={0,-1,1,-2,2,2,-2,1,-1};
int s[10][7],get[10][10];
int map[10][10];
char si;
int Judge()
{
    int ret=0;
    for(int i=1;i<=5;i++)
    {
        for(int j=1;j<=5;j++)
        {
            if(s[i][j]!=map[i][j])
            {
                ret++;
            }
        }
    }
    return ret;
}
void dfs(int now,int x,int y,int sum)
{
    if(flag!=0)
    {
        return;
    }
    int c=Judge();
    if(now==sum)
    {
        if(c==0)
        {
            flag=1;
            ans=sum;
        }
    }
    if(now-1+c>sum)
    {
        return;
    }
    for(int i=1;i<=8;i++)
    {
        int nx=x+xx[i];
        int ny=y+yy[i];
        if(nx>0 && nx<=5 && ny>0 && ny<=5)
        {
            swap(s[x][y],s[nx][ny]);
            dfs(now+1,nx,ny,sum);
            swap(s[x][y],s[nx][ny]);
        }
    }
}
int main()
{
    scanf("%d",&T);
    map[1][1]=1;
    map[1][2]=1;
    map[1][3]=1;
    map[1][4]=1;
    map[1][5]=1;
    map[2][1]=0;
    map[2][2]=1;
    map[2][3]=1;
    map[2][4]=1;
    map[2][5]=1;
    map[3][1]=0;
    map[3][2]=0;
    map[3][3]=2;
    map[3][4]=1;
    map[3][5]=1;
    map[4][1]=0;
    map[4][2]=0;
    map[4][3]=0;
    map[4][4]=0;
    map[4][5]=1;
    map[5][1]=0;
    map[5][2]=0;
    map[5][3]=0;
    map[5][4]=0;
    map[5][5]=0;
    while(T--)
    {
        int x,y;
        for(int i=1;i<=5;i++)
        {
            for(int j=1;j<=5;j++)
            {
                cin>>si;
                if(si=='*')
                {
                    x=i;
                    y=j;
                    get[i][j]=2;
                }   
                else
                {
                    get[i][j]=si-'0';
                }
            }
        }
        for(int k=0;k<=20;k++)
        {
            flag=0;
            ans=20;
            for(int i=1;i<=5;i++)
            {
                for(int j=1;j<=5;j++)
                {
                    s[i][j]=get[i][j];
                }
            }
            dfs(0,x,y,k);
            if(ans==k)
            {
                break;
            }
        }
        if(ans<=15)
        {
            printf("%d\n",ans);
        }
        else
        {
            printf("-1\n");
        }
    }
    return 0;
}

线条 发表于 2018-4-14 08:44

支持您的分享

页: [1] 2

Powered by Discuz! Archiver 7.2  © 2001-2009 Comsenz Inc.