Project Euler:Problem 68 Magic 5-gon ring
来源:互联网 发布:淘宝直播卖的东西质量 编辑:程序博客网 时间:2024/06/03 23:46
Consider the following "magic" 3-gon ring, filled with the numbers 1 to 6, and each line adding to nine.
Working clockwise, and starting from the group of three with the numerically lowest external node (4,3,2 in this example), each solution can be described uniquely. For example, the above solution can be described by the set: 4,3,2; 6,2,1; 5,1,3.
It is possible to complete the ring with four different totals: 9, 10, 11, and 12. There are eight solutions in total.
By concatenating each group it is possible to form 9-digit strings; the maximum string for a 3-gon ring is 432621513.
Using the numbers 1 to 10, and depending on arrangements, it is possible to form 16- and 17-digit strings. What is the maximum 16-digit string for a "magic" 5-gon ring?
最外圈的a0是最外圈里最小的数,所以a0<=6,同时要使得这个string最大,所以a0=6,同时最外圈的其他数分别为7,8,9,10。
1+2+3+...+9+10=55 内圈的数为1,2,3,4,5,算起来每一行的和都为14
所以a0所在的哪一行,其他两个数的和为8,而6,7都位于最外圈,所以这两个数只能是5和3
#include <iostream>#include <string>#include <vector>#include <algorithm>using namespace std;int main(){int a[7] = { 1, 2, 4, 7, 8, 9, 10 };int b[2] = { 3, 5 };string tmp,res;do{for (int i = 0; i < 2; i++){if (a[0] + b[i] + a[1] == 14 && a[1] + a[2] + a[3] == 14 && a[3] + a[4] + a[5] == 14 && a[5] + a[6] + b[(i + 1) % 2] == 14){cout << "6" << b[i] << b[(i + 1) % 2] << endl;cout << a[0] << b[(i + 1) % 2] << a[1] << endl;cout << a[2] << a[1] << a[3] << endl;cout << a[4] << a[3] << a[5] << endl;cout << a[6] << a[5] << b[i] << endl;cout << endl;}}} while (next_permutation(a, a + 7));system("pause");return 0;}
显然那个大的6531031914842725
- Project Euler:Problem 68 Magic 5-gon ring
- projecteuler No.68 Magic 5-gon ring
- Project Euler problem 68
- Project Euler - Problem 5
- Project Euler problem 5
- 【Project Euler】【Problem 5】Smallest multiple
- project euler problem 5:Smallest multiple
- Project Euler Problem 5: Smallest multiple
- Euler Project Problem 6
- project euler problem 11
- Project Euler Problem 81
- Project Euler Problem 60
- Project Euler Problem 59
- Project Euler Problem 58
- Project Euler Problem 57
- Project Euler Problem 16
- Project Euler Problem 30
- Project Euler Problem 31
- HDU 2571-----简单的DP
- chapter18test4
- iOS的主要框架介绍
- 线段树专题
- day02--课后练习
- Project Euler:Problem 68 Magic 5-gon ring
- 题目1190:大整数排序
- 如何直接强制客户端刷新.js文件
- 关于传到PHP用PHP处理计算器和js做的计算器对比
- Ant---下载,生成,编写
- uva 1252(状态压缩dp)
- 如何将json数据传回前台
- Mac新手操作指南(四)
- linux 怎么完全卸载mysql数据库