# 同心圆盘问题

3 篇文章 0 订阅

/* 同心圆盘问题 */
#include <iostream>
#include <cstring>
#include <deque>
using namespace std;

typedef deque<int> Queue;
void init(Queue &a1, Queue &a2, Queue &a3, Queue &a4);
bool is_ok(Queue a1, Queue a2, Queue a3, Queue a4);
void print(int x[]);
bool change(int x[], Queue a1, Queue a2, Queue a3, Queue a4);
void debug(Queue a1, Queue a2, Queue a3, Queue a4);
int main()
{
Queue a1, a2, a3, a4;
init(a1, a2, a3, a4);
int N = 8*8*8*8;
int s[5];
for(int i = 0; i < N; ++i)
{
memset(s, 0, sizeof(s));
int n = i;
int m = 0;
while (n != 0)
{
int c = n % 8;
n = n / 8;
s[m++] = c;
}
/*
for(int j = 0; j < 4; ++j)
cout << s[j];
cout << endl;
*/
bool ok = change(s, a1, a2, a3, a4);
// debug(a1, a2, a3, a4);
if(ok == true)
{
cout << "方案：" << endl;
print(s);
cout << "---------------------" << endl;
}
}

return 0;
}
void init(Queue &a1, Queue &a2, Queue &a3, Queue &a4)
{
a1 = {1,5,2,2,3,4,3,5};
a2 = {4,3,1,2,2,5,3,5};
a3 = {1,2,3,1,5,2,4,3};
a4 = {4,3,2,3,5,4,3,1};
}

bool is_ok(Queue a1, Queue a2, Queue a3, Queue a4)
{
// debug(a1, a2, a3, a4);
for(int i = 0; i < 8; ++i)
{
int temp = a1[i]+a2[i]+a3[i]+a4[i];
// cout << temp << endl;
if(temp != 12)
return false;
}
return true;
}

void print(int x[])
{
for(int i = 0; i < 4; ++i)
{
cout << "第" << i << "层逆时针转动" << x[i]*45 << "度。" << endl;
}
}

bool change(int x[], Queue a1, Queue a2, Queue a3, Queue a4)
{
int l1 = x[0];
int l2 = x[1];
int l3 = x[2];
int l4 = x[3];
while(l1)
{
a1.push_back(a1[0]);
a1.pop_front();
l1--;
}
while(l2)
{
a2.push_back(a2[0]);
a2.pop_front();
l2--;
}
while(l3)
{
a3.push_back(a3[0]);
a3.pop_front();
l3--;
}
while(l4)
{
a4.push_back(a4[0]);
a4.pop_front();
l4--;
}
// debug(a1, a2, a3, a4);
if(is_ok(a1, a2, a3, a4))
{
return true;
}
return false;
}
void debug(Queue a1, Queue a2, Queue a3, Queue a4)
{
for (int i = 0; i < 8; ++i)
{
cout << a1[i] << a2[i] << a3[i] << a4[i] << endl;
}
cout << "-------------------" << endl;
}

UP更新不错过~
• 0
点赞
• 3
收藏
• 打赏
• 0
评论
09-02
12-25
11-11 596
11-08
02-21 88
01-02 4850
04-14 200
10-06 264
08-29 525
04-27 1056
05-07 398
05-16 7047
06-18 1398
03-13 1796

### “相关推荐”对你有帮助么？

• 非常没帮助
• 没帮助
• 一般
• 有帮助
• 非常有帮助

from梦旅人

¥2 ¥4 ¥6 ¥10 ¥20

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、C币套餐、付费专栏及课程。