Project Euler problem 68
题意须要注意的一点就是,
序列是从外层最小的那个位置顺时针转一圈得来的。而且要求10在内圈
所以,这题暴力的话,假定最上面那个点一定是第一个点,算下和更新下即可。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <set>
#include <vector>
#include <map>
#define MAXN 111
#define MAXM 55555
#define INF 1000000007
using namespace std;
int a[12];
int sum[6];
string ans, tmp;
int main()
{
int n = 10;
int first = 1;
ans = "", tmp = "";
for(int i = 1; i <= n; i++) a[i] = i;
do {
int pos = 1;
for(int i = 1; i <= 5; i++) {
if(a[i] < a[pos]) pos = i;
int z = i + 6;
if(z > 10) z = z - 5;
sum[i] = a[i] + a[i + 5] + a[z];
}
if(pos != 1) continue;
int flag = 1;
for(int i = 2; i <= 5; i++)
if(sum[i] != sum[i - 1]) flag = 0;
if(sum[1] != sum[5]) flag = 0;
for(int i = 6; i <= 10; i++) {
if(a[i] == 10) flag = 0;
}
tmp = "";
if(flag) {
for(int i = 1; i <= 5; i++) {
int z = i + 6;
if(z > 10) z = z - 5;
tmp += (a[i] + 'a');
tmp += (a[i + 5] + 'a');
tmp += (a[z] + 'a');
}
if(!first) {
if(ans < tmp) ans = tmp;
} else {
ans = tmp;
first = 1;
} }
}while(next_permutation(a + 1, a + n + 1));
for(int i = 0; i < 15; i++) printf("%d", ans[i] - 'a');
return 0;
}
Project Euler problem 68的更多相关文章
- Project Euler Problem 10
Summation of primes Problem 10 The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of ...
- Project Euler problem 62
题目的大意很简单 做法的话. 我们就枚举1~10000的数的立方, 然后把这个立方中的有序重新排列,生成一个字符串s, 然后对于那些符合题目要求的肯定是生成同一个字符串的. 然后就可以用map来搞了 ...
- Project Euler problem 63
这题略水啊 首先观察一下. 10 ^ x次方肯定是x + 1位的 所以底数肯定小于10的 那么我们就枚举1~9为底数 然后枚举幂级数就行了,直至不满足题目中的条件即可break cnt = 0 for ...
- Project Euler problem 61
题意很明了. 然后我大概的做法就是暴搜了 先把每个几边形数中四位数的处理出来. 然后我就DFS回溯着找就行了. 比较简单吧. #include <cstdio> #include < ...
- Project Euler Problem 675
ORZ foreverlasting聚聚,QQ上问了他好久才会了这题(所以我们又聊了好久的Gal) 我们先来尝试推导一下\(S\)的性质,我们利用狄利克雷卷积来推: \[2^\omega=I\ast| ...
- Project Euler Problem (1~10)
1.If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. Th ...
- Project Euler Problem 26-Reciprocal cycles
看样子,51nod 1035 最长的循环节 这道题应该是从pe搬过去的. 详解见论文的(二)那部分:http://web.math.sinica.edu.tw/math_media/d253/2531 ...
- Project Euler Problem 24-Lexicographic permutations
全排列的生成,c++的next_permutation是O(n)生成全排列的.具体的O(n)生成全排列的算法,在 布鲁迪 的那本组合数学中有讲解(课本之外,我就看过这一本组合数学),冯速老师翻译的,具 ...
- Project Euler Problem 23-Non-abundant sums
直接暴力搞就行,优化的地方应该还是计算因子和那里,优化方法在这里:http://www.cnblogs.com/guoyongheng/p/7780345.html 这题真坑,能被写成两个相同盈数之和 ...
随机推荐
- Java 字符串格式化 String.format() 的使用
常规类型的格式化 String类的format()方法用于创建格式化的字符串以及连接多个字符串对象.熟悉C语言的同学应该记得c语言的sprintf()方法,两者有类似之处.format()方法有两种重 ...
- CAD实现批量打印(网页版)
主要用到函数说明: IMxDrawPrint::BatchPrintDialog 批量打印对话框,详细说明如下: 参数 说明 [in] IMxDrawResbuf* pParam 批量打印位置参数, ...
- Java IO(三)--字节流基本使用
I/O流分类: InputStream和Read的子类都有read(),用来读取单个字节或字节数组 OutputStream和write的子类都有write(),用来写入单个字节或字节数组 一般都是通 ...
- SQL Server 兼容级别
ALTER DATABASE (Transact-SQL) 兼容级别 适用对象:SQL Server(从 2008 版开始)Azure SQL 数据库Azure SQL 数据仓库并行数据仓库 将某些数 ...
- buf.entries()详解
buf.entries() 返回:{Iterator} 从当前 Buffer 的内容中,创建并返回一个 [index, byte] 形式的迭代器. const buf = Buffer.from('b ...
- JS 去除字符串空格
$.trim()是jQuery提供的函数,用于去掉字符串首尾的空白字符. "abc 123 def".replace(/\s/g, "") 去除所有的空格
- codeforces 407 div1 A题(Functions again)
codeforces 407 div1 A题(Functions again) Something happened in Uzhlyandia again... There are riots on ...
- STM32F407 新建基于固件库的项目模板
1.新建文件夹如图: 2.新建项目在USER文件夹中,选cpu如图: 若再弹出窗口, 直接点cancel 3.删了这俩文件夹: 4.复制文件到fwlib: src 存放的是固件库的.c 文件, inc ...
- jquery对JSON字符串的解析--eval函数
jquery eval解析JSON中的注意点介绍----https://www.jb51.net/article/40842.htm
- CookiesReader
CookiesReader "use strict"; /** * * @author xgqfrms * @license MIT * @copyright xgqfrms * ...