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 这题真坑,能被写成两个相同盈数之和 ...
随机推荐
- anchor_target_layer中的bounding regression
在anchor_target层,这两行是计算bounding regression代码: bbox_targets = np.zeros((len(inds_inside), 4), dtype=np ...
- 实现UAC对话框效果
设置桌面全屏: int cxScreen,cyScreen; cxScreen=GetSystemMetrics(SM_CXSCREEN); cyScreen=GetSystemMetrics(SM_ ...
- spring的设计思想
在学习Spring框架的时候, 第一件事情就是分析Spring的设计思想 在学习Spring的时候, 需要先了解耦合和解耦的概念 耦合: 简单来说, 在软件工程当中, 耦合是指对象之间的相互依赖 耦合 ...
- 第2节 mapreduce深入学习:13、mapreduce的整个运行过程(多看几遍)
两个问题: 1.mapTaks的个数怎么确认:与block块相关2.reducetask的个数怎么确认:没法确认,需要反复的设置尝试,找到最优值. 手动进行设置 job.setNumReduceTa ...
- vs2008如何新建自己工程的环境变量(局部)和 Windows系统(全局). .
在vs2008的Project->Property设置里经常会看到类似$(IntDir).$(OutDir).$(ProjectName) 的预定义宏.以vc2008为例,有时候我们在引用别的库 ...
- 跳转QQ聊天窗口
1. 点击按钮跳转QQ聊天窗口,若不是好友,先加好友 <a href=" tencent://message/?uin=QQ号" target="_blank&qu ...
- TortoiseSVN文件夹操作
(1).安装SVN·客户端 (2) 建立库: 1.新建文件夹,目录和文件夹名称最好都用英文,不要使用中文: 2.打开文件夹,在空白处按下“shift键+鼠标右键”: 3.在弹出的菜单中选择“Torto ...
- 大项目之网上书城(六)——个人页面和书页面Demo
目录 大项目之网上书城(六)--个人页面和书页面Demo 主要改动 1.user.jsp 代码 效果图 user.js 代码 3.shu.jsp 代码 效果图 4.其他小改动 LoginServlet ...
- Python 字符编码-文件处理
.read #读取所有内容,光标移动到文件末尾.readable #判断文件是否可读.readline #读取一行内容,光标移动到第二行首部.readlines #读取每一行内容,存放于列表中.wri ...
- 使用ajax解析后台json数据时:Unexpected token o in JSON at position 1
json数据解析异常 今天在做json数据的时候,出现了如下错误,说是解析异常. VM1584:1 Uncaught SyntaxError: Unexpected token o in JSON a ...