2 qq 31459657 qq_31459657 于 2017.09.01 23:39 提问

POJ1166 求问错在哪里?
poj

原题地址
http://bailian.openjudge.cn/practice/2814/

我的答案:
#include
#include
using namespace std;

void op(int a[],int i,int num)
{
for(int j=0;j<num;j++)
{

switch(i)
{
    case 1:a[0]++;a[1]++;a['d'-'a']++;a['e'-'a']++;break;
    case 2:a[0]++;a[1]++;a[2]++;break;
    case 3:a['b'-'a']++;a['c'-'a']++;a['e'-'a']++;a['f'-'a']++;break;
    case 4:a[0]++;a['d'-'a']++;a['g'-'a']++;break;
    case 5:a['b'-'a']++;a['d'-'a']++;a['e'-'a']++;a['f'-'a']++;a['h'-'a']++;break;
    case 6:a['c'-'a']++;a['f'-'a']++;a['i'-'a']++;break;
    case 7:a['d'-'a']++;a['e'-'a']++;a['g'-'a']++;a['h'-'a']++;break;
    case 8:a['g'-'a']++;a['h'-'a']++;a['i'-'a']++;break;
    case 9:a['e'-'a']++;a['f'-'a']++;a['h'-'a']++;a['i'-'a']++;break;
    default:break;
}
for(int i=0;i<9;i++)
{
    a[i]%=4;
}
}

}

int main()
{
int now[9];
int temp[9];
int slove[9]={0};
int outnum[9];
int minnum = 10000;
int tempmin=0;

for(int i=0;i<9;i++)
{
   cin>>temp[i];
}

memcpy(now,temp,sizeof(now));

for(int i=0;i<4;i++)
{
    op(now,1,i);
    slove[0] = i;

    for(int j=0;j<4;j++)
    {
         op(now,2,j);
         slove[1] = j;

        for(int k=0;k<4;k++)
        {
            op(now,3,k);
            slove[2] = k;

            for(int i2 = 0;i2<2;i2++)
            {
                for(int j2=0;j2<3;j2++)
                {
                    if(now[3*i2+j2])
                    {
                        int opnum = 4 - now[3*i2+j2];
                        slove[3*i2+j2+3] = opnum;
                        op(now,3*i2+j2+1+3,opnum);
                    }
                    else
                    {
                        slove[3*i2+j2+3] = 0;
                    }

                }
            }

          if(now[6]== 0 && now[7] == 0 && now[8] == 0)
            {


                        tempmin=0;
                        for(int p=0;p<9;p++)
                        {
                            for(int o=0;o<slove[p];o++)
                            {
                                tempmin++;
                            }
                        }
                        if(tempmin < minnum)
                        {
                            minnum = tempmin;
                            memcpy(outnum,slove,sizeof(outnum));
                        }

            }
             memcpy(now,temp,sizeof(now));
        }

    }
}

int cur = 0;
for (cur = 0; cur < 9; cur++)
while (outnum[cur]--)
cout<<cur + 1<<" ";
return 0;
}

1个回答

caozhy
caozhy   Ds   Rxr 2017.09.03 17:18
Csdn user default icon
上传中...
上传图片
插入图片