题意很明了。

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

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

然后我就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. Xml解析之——Java/Android/Python

    Xml解析之——Java/Android/Python 一.Xml文件 test.xml <note> <to>George</to> <from>Jo ...

  2. Asp.net 事务处理

    事务处理是在数据处理时经常遇到的问题,经常用到的方法有以下三种总结整理如下:方法1:直接写入到sql 中在存储过程中使用 BEGIN TRANS, COMMIT TRANS, ROLLBACK TRA ...

  3. 在eclipse中新建Dynamic web project时选择2.5和3.0的区别(里面涉及servlet和tomcat的问题)

    1.是指servlet的版本,是2.5的还是3.0的 servlet3.0以后支持异步 2.dynamic web module和对应的TOMCAT 版本 http://blog.sina.com.c ...

  4. Java中异常的基本应用(一)

    在Java中,我们把异常当做一种对象来处理,正是异常机制的引入,使得我们的程序更加健壮.异常指示了一个不正常的条件,或者一个错误条件,简单地说就是一个中断了正常的指令流的事件.程序控制将无条件的抛至一 ...

  5. recvmsg和sendmsg函数

    这两个函数是最通用的I/O函数.实际上我们把所有read.readv.recv和recvfrom调用替换成recvmsg调用.类似地,各种输出函数调用也可以替换成sendmsg调用 #include ...

  6. 用 javascript 判断 IE 版本号

    原文地址: http://julying.com/blog/determine-the-version-number-of-ie-with-javascript/ var _IE = (functio ...

  7. 安装 vsftp

    1.yum安装 vsftp yum list vsftpd yum install vsftpd 2.配置 vsftp 将root注释掉 vi /etc/vsftpd/ftpusers 将root注释 ...

  8. .NET,你真的 知道了吗

    搞清自己是干什么的 有人问你是做什么的,回答是:"我是做,NET开发的",有的人也会问:"那.NER.是什么?"刚开始我认为是一个开打工具,后认为是一个平台,一 ...

  9. copy(source,destination)拷贝文件

    source 必须 规定要复制的文件 destination 复制文件的目的地 说明 :将文件从 source 拷贝到 destination.如果成功则返回 TRUE,否则返回 FALSE. 例如: ...

  10. python学习第一课要点记录

    写在要点之前的一段话,留给将来的自己:第一次参加编程的培训班,很兴奋很激动,之前都是自己在网上找免费的视频来看,然后跟着写一些课程中的代码,都是照着模子写,没有自己过多的思考.感觉这样学不好,除了多写 ...