题意很明了。

然后我大概的做法就是暴搜了

先把每个几边形数中四位数的处理出来。

然后我就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的更多相关文章

  1. 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 ...

  2. Project Euler problem 62

    题目的大意很简单 做法的话. 我们就枚举1~10000的数的立方, 然后把这个立方中的有序重新排列,生成一个字符串s, 然后对于那些符合题目要求的肯定是生成同一个字符串的. 然后就可以用map来搞了 ...

  3. Project Euler problem 63

    这题略水啊 首先观察一下. 10 ^ x次方肯定是x + 1位的 所以底数肯定小于10的 那么我们就枚举1~9为底数 然后枚举幂级数就行了,直至不满足题目中的条件即可break cnt = 0 for ...

  4. Project Euler problem 68

    题意须要注意的一点就是, 序列是从外层最小的那个位置顺时针转一圈得来的.而且要求10在内圈 所以,这题暴力的话,假定最上面那个点一定是第一个点,算下和更新下即可. #include <iostr ...

  5. Project Euler Problem 675

    ORZ foreverlasting聚聚,QQ上问了他好久才会了这题(所以我们又聊了好久的Gal) 我们先来尝试推导一下\(S\)的性质,我们利用狄利克雷卷积来推: \[2^\omega=I\ast| ...

  6. 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 ...

  7. Project Euler Problem 26-Reciprocal cycles

    看样子,51nod 1035 最长的循环节 这道题应该是从pe搬过去的. 详解见论文的(二)那部分:http://web.math.sinica.edu.tw/math_media/d253/2531 ...

  8. Project Euler Problem 24-Lexicographic permutations

    全排列的生成,c++的next_permutation是O(n)生成全排列的.具体的O(n)生成全排列的算法,在 布鲁迪 的那本组合数学中有讲解(课本之外,我就看过这一本组合数学),冯速老师翻译的,具 ...

  9. Project Euler Problem 23-Non-abundant sums

    直接暴力搞就行,优化的地方应该还是计算因子和那里,优化方法在这里:http://www.cnblogs.com/guoyongheng/p/7780345.html 这题真坑,能被写成两个相同盈数之和 ...

随机推荐

  1. (转)ThinkPHP自定义标签

    第一:在当前应用下的Conf文件夹中config.php加两个配制项:             'TAGLIB_LOAD' => true,//加载标签库打开             'APP_ ...

  2. 【转】iOS开发系列--数据存取

    原文: http://www.cnblogs.com/kenshincui/p/4077833.html#SQLite 概览 在iOS开发中数据存储的方式可以归纳为两类:一类是存储为文件,另一类是存储 ...

  3. Linux服务器指令

    1.查看cpu信息:/proc/cpuinfo2.查看内存信息:/prco/meminfo3.查看服务器版本信息:cat /etc/issue4.服务器系统位数:uname -a5.网卡信息:ifco ...

  4. QQ情侣头像~

                       

  5. php 文件操作之抓取网站图片

    $str= file_get_contents("http://v.qq.com/");preg_match_all("/\<img\s+src=.*\s*\> ...

  6. .ctor,.cctor 以及 对象的构造过程

    摘要: .ctor,.cctor 以及 对象的构造过程.ctor:简述:构造函数,在类被实例化时,它会被自动调用.当C#的类被编译后,在IL代码中会出现一个名为.ctor的方法,它就是我们的构造函数, ...

  7. JQUERY1.9学习笔记 之基本过滤器(八) 最后元素选择器

    最后元素选择器 jQuery( ":last" ) 描述:选择与之匹配的最后元素. 例:选择表格的最后一行. <!DOCTYPE html><html lang= ...

  8. Sql 格式化工具

    SQL Pretty Printer:目前提供4种使用方式,桌面版本,SSMS(SQL Server Management Studio)插件,VS插件,和提供API接口. SQL Pretty Pr ...

  9. struts2.xml的配置与技巧

    <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-/ ...

  10. 基类中定义的虚函数在派生类中重新定义时,其函数原型,包括返回类型、函数名、参数个数、参数类型及参数的先后顺序,都必须与基类中的原型完全相同 but------> 可以返回派生类对象的引用或指针

      您查询的关键词是:c++primer习题15.25 以下是该网页在北京时间 2016年07月15日 02:57:08 的快照: 如果打开速度慢,可以尝试快速版:如果想更新或删除快照,可以投诉快照. ...