Project Euler problem 61
题意很明了。
然后我大概的做法就是暴搜了
先把每个几边形数中四位数的处理出来。
然后我就DFS回溯着找就行了。
比较简单吧。
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
using namespace std;
vector<int>g[7], v[7][10000];
int vis[7];
void get_three()
{
for(int i = 1; ; i++)
{
int x = i * (i + 1) / 2;
if(x >= 10000) break;
if(x >= 1000) g[0].push_back(x);
}
}
void get_four()
{
for(int i = 1; ; i++)
{
int x = i * i;
if(x >= 10000) break;
if(x >= 1000) g[1].push_back(x);
}
}
void get_five()
{
for(int i = 1; ; i++)
{
int x = i * (3 * i - 1) / 2;
if(x >= 10000) break;
if(x >= 1000) g[2].push_back(x);
}
}
void get_six()
{
for(int i = 1; ; i++)
{
int x = i * (2 * i - 1);
if(x >= 10000) break;
if(x >= 1000) g[3].push_back(x);
}
}
void get_seven()
{
for(int i = 1; ; i++)
{
int x = i * (i * 5 - 3) / 2;
if(x >= 10000) break;
if(x >= 1000) g[4].push_back(x);
}
}
void get_eight()
{
for(int i = 1; ; i++)
{
int x = i * (3 * i - 2);
if(x >= 10000) break;
if(x >= 1000) g[5].push_back(x);
}
}
int a[7];
int ans;
int flag;
void dfs(int deep)
{
if(flag) return;
if(deep == 6)
{
if(a[5] % 100 == a[0] / 100)
{
flag = 1;
printf("%d\n", a[0] + a[1] + a[2] + a[3] + a[4] + a[5]);
return;
}
}
for(int i = 0; i < 6; i++)
{
if(!vis[i])
{
for(int j = 0; j < g[i].size(); j++)
{
int y = g[i][j];
if(!deep || y / 100 == a[deep - 1] % 100)
{
vis[i] = 1;
a[deep] = y;
dfs(deep + 1);
vis[i] = 0;
}
}
}
}
}
int main()
{
get_three();
get_four();
get_five();
get_six();
get_seven();
get_eight();
dfs(0);
return 0;
}
Project Euler problem 61的更多相关文章
- 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 68
题意须要注意的一点就是, 序列是从外层最小的那个位置顺时针转一圈得来的.而且要求10在内圈 所以,这题暴力的话,假定最上面那个点一定是第一个点,算下和更新下即可. #include <iostr ...
- 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 这题真坑,能被写成两个相同盈数之和 ...
随机推荐
- OUTPUT 在insnert delete update 的神奇功效
Inserted deleted 个人理解 应该是两个 临时表 分别存储 变动后的数据集 和 变动前的数据集 使用例子: 1.对于INSERT,可以引用inserted表以查询新行的属性 ...
- 关于图表的JS插件
http://echarts.baidu.com/ http://echarts.baidu.com/tutorial.html#5%20%E5%88%86%E9%92%9F%E4%B8%8A%E6% ...
- 离线安装maven,重新打开eclipse报错处理方法
报错截图如下 1.eclipse 添加 jre Window -> Preferences -> Java -> Installed JREs If you can’t find a ...
- struts1、ajax、jquery、json简单实例
1.页面ajax代码,使用$.ajax,获得json对象后each $.ajax({ type:"GET", url:ctx + "/uploadImg.do" ...
- JQUERY1.9学习笔记 之内容过滤器(二) 空元素选择器
描述:选择没有子元素(包括文本节点)的标签. jQuery(":empty") 与:parent相反. 例:找出所有为空的元素.(他们没有子元素或文本元素). <!docty ...
- HTML5 canvas生成图片马赛克特效插件
HTML5 canvas生成图片马赛克特效插件 简要教程 这是一款使用html5 canvas来将图片制作成马赛克效果的js插件.该插件的灵感来自于美国肖像画家Chuck Close.已经有人使用这个 ...
- UVA - 1614 Hell on the Market(贪心)
Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Submit Status Descript ...
- [转载] $\mathrm{Jordan}$标准型的介绍
本文转载自陈洪葛的博客$,$ 而实际上来自xida博客朝花夕拾$,$ 可惜该博客已经失效 $\mathrm{Jordan}$ 标准形定理是线性代数中的基本定理$,$ 专门为它写一篇长文好像有点多余$: ...
- hdu 2197 本原串
http://acm.hdu.edu.cn/showproblem.php?pid=2197 长度为n的01串有2的n次方个,再减去不符合要求的.不符合要求的字符串就是长度为n的约数的字符串. 递归处 ...
- new Random().nextInt
public static void main(String[] args) { System.out.println(new Random().nextInt(0)); } Exception in ...