{
  "question_id": 1083775,
  "question_title": "六角填数",
  "question_content": "<p>![图片说明](https://img-ask.csdn.net/upload/202006/14/1592104139_240178.png)\n六角填数\n题目描述\n如下图所示六角形中，有12个点，依次填入1~12的数字，使得每条直线上的数字之和都相同。其中，已经替你填好了点1，2，3的数字，请你计算其他位置所代表的数字是多少？\n输入\n输入仅一行，以空格隔开，分别表示已经填好的点1,2,3的数字。\n输出\n输出仅一行，以空格隔开，分别表示所有位置所代表的数字。\n样例输入：\n1 8 2\n样例输出：\n1 8 2 9 7 11 10 12 3 5 6 4</p>",
  "difficulty": "困难",
  "answer_id": 1290115,
  "answer_content": "\n```\n#include <iostream>\n#include <cmath>\n#include <cstdio>\n#include <cstring>\nusing namespace std;\n\n#define eps 10e-10\n#define N 15\n\nint a[N];\nbool vis[N];\n\nvoid dfs(int x){\n    if(x == 1 || x == 2 || x == 3){\n        dfs(x+1);\n        return ;\n    }\n    if(x > 12){\n        int t[6];\n        t[0] = a[1] + a[3] + a[6] + a[8];\n        t[1] = a[1] + a[4] + a[7] + a[11];\n        t[2] = a[2] + a[3] + a[4] + a[5];\n        t[3] = a[2] + a[6] + a[9] + a[12];\n        t[4] = a[8] + a[9] + a[10] + a[11];\n        t[5] = a[12] + a[10] + a[7] + a[5];\n\n        for(int i = 1; i < 6; ++i){\n            if(t[i] != t[i-1])return ;\n        }\n\t\tfor (int i = 1; i <= 12; i++) cout << a[i] << \" \";\n        return ;\n    }\n\n    for(int i = 1;i < 13; ++i){\n        if(!vis[i]){\n            vis[i] = 1;\n            a[x] = i;\n            dfs(x+1);\n            vis[i] = 0;\n        }\n    }\n\n\n}\n\nint main(){\n    memset(vis,0,sizeof(vis));\n    cin >> a[1];\n\tvis[a[1]] = 1;\n    cin >> a[2];\n\tvis[a[2]] = 1;\n    cin >> a[3];\n\tvis[a[3]] = 1;\n    dfs(1);\n    return 0;\n}\n\n```\n![图片说明](https://img-ask.csdn.net/upload/202006/14/1592106523_783342.png)\n\n# lz你刚来，长点心吧，这里很多人看似在回答你问题，实际上都是投机取巧胡乱抄袭。\n",
  "tag_name": "c++",
  "cpp": "#include <iostream>\n#include <cmath>\n#include <cstdio>\n#include <cstring>\nusing namespace std;\n#define eps 10e-10\n#define N 15\nint a[N];\nbool vis[N];\nvoid dfs(int x){\n\tif(x == 1 || x == 2 || x == 3){\n\t\tdfs(x+1);\n\t\treturn ;\n\t}\n\tif(x > 12){\n\t\tint t[6];\n\t\tt[0] = a[1] + a[3] + a[6] + a[8];\n\t\tt[1] = a[1] + a[4] + a[7] + a[11];\n\t\tt[2] = a[2] + a[3] + a[4] + a[5];\n\t\tt[3] = a[2] + a[6] + a[9] + a[12];\n\t\tt[4] = a[8] + a[9] + a[10] + a[11];\n\t\tt[5] = a[12] + a[10] + a[7] + a[5];\n\t\tfor(int i = 1; i < 6; ++i){\n\t\t\tif(t[i] != t[i-1])return ;\n\t\t}\n\t\tfor (int i = 1; i <= 12; i++) cout << a[i] << \" \";\n\t\treturn ;\n\t}\n\tfor(int i = 1;i < 13; ++i){\n\t\tif(!vis[i]){\n\t\t\tvis[i] = 1;\n\t\t\ta[x] = i;\n\t\t\tdfs(x+1);\n\t\t\tvis[i] = 0;\n\t\t}\n\t}\n}\nint main(){\n\tmemset(vis,0,sizeof(vis));\n\tcin >> a[1];\n\tvis[a[1]] = 1;\n\tcin >> a[2];\n\tvis[a[2]] = 1;\n\tcin >> a[3];\n\tvis[a[3]] = 1;\n\tdfs(1);\n\treturn 0;\n}",
  "topic_link": "https://bbs.csdn.net/topics/600470159",
  "status": 1,
  "keywords": "图算法,算法高阶,图的表示,基本的图算法",
  "license": "csdn.net",
  "notebook": {
    "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/56.ipynb?type=file"
  },
  "notebook_enable": 1,
  "author": "qq_32724981"
}