A spider, S, sits in one corner of a cuboid room, measuring 6 by 5 by 3, and a fly, F, sits in the opposite corner. By travelling on the surfaces of the room the shortest "straight
line" distance from S to F is 10 and the path is shown on the diagram.


However, there are up to three "shortest" path candidates for any given cuboid and the shortest route doesn't always have integer length.

It can be shown that there are exactly 2060 distinct cuboids, ignoring rotations, with integer dimensions, up to a maximum size of M by M by M, for which the shortest route has integer
length when M = 100. This is the least value of M for which the number of solutions first exceeds two thousand; the number of solutions when M = 99 is 1975.

Find the least value of M such that the number of solutions first exceeds one million.

高中做过的题目。把立方体各面展开,这个路径实际上是一个直角三角形的斜边。

要使得的这个路径最小。如果矩阵个边长分别为a<=b <=c

最短路径为sqrt((a+b)^2+c^2)

把a,b视为总体,记做ab

则ab范围是[2,2M]

在寻找到开方后结果为整数的ab和c后

假设ab<c:a,b是能够平均分ab的

假设ab>=c:b的取值到大于ab/2而且满足b<=c,ab-b<=c 得到b的取值个数为(c-(ab+1)/2)+1

#include <iostream>
#include <string>
#include <cmath>
using namespace std; int main()
{
int c = 1;
int count = 0;
while (count < 1000000)
{
c++;
for (int ab = 2; ab <= 2 * c; ab++)
{
int path=ab*ab + c*c;
int tmp = int(sqrt(path));
if (tmp*tmp == path)
{
count += (ab >= c) ? 1+(c-(ab+1)/2) : ab / 2;
}
}
}
cout << c << endl;
system("pause");
return 0;
}

Project Euler:Problem 86 Cuboid route的更多相关文章

  1. Project Euler:Problem 55 Lychrel numbers

    If we take 47, reverse and add, 47 + 74 = 121, which is palindromic. Not all numbers produce palindr ...

  2. Project Euler:Problem 63 Powerful digit counts

    The 5-digit number, 16807=75, is also a fifth power. Similarly, the 9-digit number, 134217728=89, is ...

  3. Project Euler:Problem 76 Counting summations

    It is possible to write five as a sum in exactly six different ways: 4 + 1 3 + 2 3 + 1 + 1 2 + 2 + 1 ...

  4. Project Euler:Problem 87 Prime power triples

    The smallest number expressible as the sum of a prime square, prime cube, and prime fourth power is ...

  5. Project Euler:Problem 89 Roman numerals

    For a number written in Roman numerals to be considered valid there are basic rules which must be fo ...

  6. Project Euler:Problem 93 Arithmetic expressions

    By using each of the digits from the set, {1, 2, 3, 4}, exactly once, and making use of the four ari ...

  7. Project Euler:Problem 39 Integer right triangles

    If p is the perimeter of a right angle triangle with integral length sides, {a,b,c}, there are exact ...

  8. Project Euler:Problem 28 Number spiral diagonals

    Starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral is forme ...

  9. Project Euler:Problem 47 Distinct primes factors

    The first two consecutive numbers to have two distinct prime factors are: 14 = 2 × 7 15 = 3 × 5 The ...

随机推荐

  1. javascript 获取服务时间

    用到了jquery的ajax方法,ajax自己写也可以. 具体用法 var setId = setInterval(function(){ var xhr = $.ajax({ type: 'HEAD ...

  2. webstorm 打开后 一直停留在scanning files to index....,或跳出内存不够的提示框

    用着有时会这样,超级卡, 网上搜了下,原来如此,记录下,免得忘了. ------------------------- 说明: 在npm install 后,会出现Scanning files to ...

  3. 关于 Blog 修改

    关于 Blog 修改 本 Blog 使用的是 WordPress,每次升级 WordPress 都需要修改文件,以修正一些问题,因此做个总记录,便于自己修改. 解决 WordPress 无法打开中文链 ...

  4. CSS技巧教程:margin在IE中的表现

    margin的位移方向是指margin数值为正值时候的情形,如果是负值则位移方向相反. 如上图所示:黄色子元素盒的margin-top,margin-left为负值时,如-10px,则黄色子元素盒向上 ...

  5. .net core Web应用启动类

    在ASP.NET Core中,Startup类为Web应用的入口类,用于配置Web服务的管道/过滤器以及Web应用所能用到的服务.在启动Web应用后,ASP.NET将在主库中查询名为Startup的类 ...

  6. c#多线程调用有参数的方法

      Thread (ParameterizedThreadStart) 初始化 Thread 类的新实例,指定允许对象在线程启动时传递给线程的委托.   Thread (ThreadStart) 初始 ...

  7. python字典的排序

    # -*- coding:UTF-8 -*- def dict_sort(): # 按照value的值从大到小的顺序进行排序 dic = {'a': 31, 'bc': 5, 'c': 3, 'asd ...

  8. 使用iCarousel的旋转木马效果请求图片

    使用iCarousel的旋转木马效果请求图片 https://github.com/nicklockwood/iCarousel 先看看效果: 源码如下: // // RootViewControll ...

  9. FDFDF

    Linux(Centos)之安装Nginx及注意事项   1.Nginx的简单说明 a.  Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器,期初开发的目的 ...

  10. git使用教程2-更新github上代码

    前面一篇已经实现首次上传代码到github了,迈出了装逼第一步,本篇继续讲如何把本地更新的代码同步更新到github上 一.clone代码 1.把大神的代码clone到本地,或者clone自己gith ...