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 这题真坑,能被写成两个相同盈数之和 ...
随机推荐
- react router activeclassName 没有显示
import React, {Component} from 'react' import {NavLink, Switch, Route, Redirect} from 'react-router- ...
- python day one
今日内容: python基础: 一 编程语言 什么是编程语言? 上面提及的能够被计算机所识别的表达方式即编程语言,语言是沟通的介质,而编程语言是程序员与计算机沟通的介质.在编程的世界里,计算机更像是人 ...
- secureCRT 破解
转自:http://www.cnblogs.com/qingtingzhe/articles/5008902.html
- gulp(1) 的使用
1.安装node.js 2.全局安装gulp.js npm install gulp -g 3.在项目本地根目录再安装(通过黑窗口安装)npm install --save-dev gulp/ 或者 ...
- Python 3安装体验篇(win10)
一.下载 1.打开官网https://www.python.org/downloads/windows/,点击Python 3版本链接 2.点击win10 64位安装链接,即可下载Python安装 二 ...
- selenium3 简单使用
from selenium import webdriverimport time browser = webdriver.Chrome()url = 'https://baidu.com' brow ...
- nativeLibraryDirectories=[/data/app/com.lukouapp-1/lib/arm64, /vendor/lib64, /system/lib64]]] couldn't find "libxxxx.so
一开始我遇到的问题是,如果手机有SD卡槽,则不管有没有插卡,都会闪退,打日记后发现是找不到so文件.报错日记如下: nativeLibraryDirectories=[/data/app/com.lu ...
- HTML基础知识 table中 th,td,tr
https://www.2cto.com/kf/201711/701872.html table是一个布局神器,之前看过很多代码,都是用table布局的.但是,我在学习的过程中,发现table有很迷的 ...
- Android BGABadgeView:BGABadgeImageView以及BGABadgeRelativeLayout(4)
Android BGABadgeView:BGABadgeImageView以及BGABadgeRelativeLayout(4) 在附录文章5,6,7的基础上,写一个小例子说明BGABadge ...
- WebLoad 脚本的用法
WebLoad 对于模拟一个HTTP 请求,一般都是 由以下三部分组成,并把这三部分包在一个Transaction里(从BeginTransation 到 EndTransaction 为止): ...