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. "Error: ANDROID_HOME is not set and "android" command not in your PATH. You must fulfill at least one of these conditions.".

    设置环境变量 set ANDROID_HOME=C:\\android-sdk-windows set PATH=%PATH%;%ANDROID_HOME%\tools;%ANDROID_HOME%\ ...

  2. 普通平衡树Tyvj1728、luogu P3369 (splay)

    存个模板,这次是splay的: 题目见这个题解: <--(鼠标移到这儿) 代码如下: #include<cstdio> #define INF 2147483647 using na ...

  3. input自定义样式上传图片

    在我们写网页的时候,有很多各种各样的上传图片的样式,但是input 的 type="file" 的样式是不可被更改的. 其实我们要的只是input的点击,清楚这点就行了. CSS部 ...

  4. 使用ArcGIS Chef Cookbook轻松搞掂WebGIS平台部署

    1.安装Chef Client v12版本. 2.复制arcgis cookbook资源到Chef安装目录. 3.考虑到一般部署的服务器环境无法连接互联网,所以需要事先部署ArcGIS Cookboo ...

  5. MySQL数据库(13)----忘记root用户密码解决方案【转载】

    1.首先确认服务器出于安全的状态,也就是没有人能够任意地连接MySQL数据库. 因为在重新设置MySQL的root密码的期间,MySQL数据库完全出于没有密码保护的 状态下,其他的用户也可以任意地登录 ...

  6. sqlserver变量的生周期

    在声明一个变量后,一旦遇到分号或者go,生命周期就结 DECLARE @num1 int --go ; --go print @num1; --print @num1:

  7. VS :不会命中断点 代码版本与原始版本不同

    设置了断点,但是无法中断,提示"不会命中断点 代码版本与原始版本不同".这种情况下一般是生成的bin\debug下面的文件与实际代码不符. 但是这次确实没有问题,重新更新程序,清理 ...

  8. 使用PowerShell批量注册DLL到GAC

    一段很小的代码,注册当前目录下所有的DLL到GAC,请先把gacutil.exe复制到同一个目录. $Path = Get-Location $Dir = Get-ChildItem "$P ...

  9. July 30th 2017 Week 31st Sunday

    Eternity is not a distance, but a decision. 永恒不是一段距离,而是一种决定. What can be called as eternity? Wealth ...

  10. 78、WebClient实现上传下载 System.Net、System.Uri类

    高层类.使用简单.均支持异步版本.支持http,https,fpt,files等URI. 一.下载 方法: Stream= client.OpenRead(serverUri): 打开一个可读的流.对 ...