Project Euler:Problem 86 Cuboid route
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的更多相关文章
- Project Euler:Problem 55 Lychrel numbers
If we take 47, reverse and add, 47 + 74 = 121, which is palindromic. Not all numbers produce palindr ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- Canvas学习:globalCompositeOperation详解
在默认情况之下,如果在Canvas之中将某个物体(源)绘制在另一个物体(目标)之上,那么浏览器就会简单地把源特体的图像叠放在目标物体图像上面. 简单点讲,在Canvas中,把图像源和目标图像,通过Ca ...
- 【一些简单的jQuery选择器】
学习[js DOM 编程艺术],最后面有许多jQuery的选择器,每个都动手敲了一遍. jQuery 提供了高级选择器的方法. js获取元素的三个基本方法分别是通过标签名,类名和id,即(getEle ...
- .NET开源论坛MvcForum推荐
MvcForum算是Asp.net中开源论坛佼佼者之一.主要使用ASP.NET MVC 5 &Unity & Entity Framework 6,有较强的可撸性.是论坛开发者的不二之 ...
- Nuget Tips
Install-Package时老是提示找不到Available Source,研究了下Nuget Package Manager的配置.发现有两个地方可以改: 1.Visual Studio中Too ...
- Unity射线
//射线原点 [SerializField] Transform tr; //射线长度 [SerializField] float dis = 5; //射线停留时间 [SerializFiel ...
- C#多线程顺序依赖执行控制
在开发过程中,经常需要多个任务并行的执行的场景,同时任务之间又需要先后依赖的关系.针对这样的处理逻辑,通常会采用多线程的程序模型来实现. 比如A.B.C三个线程,A和B需要同时启动,并行处理,且B需要 ...
- 京东原来你运用的这玩意,不错,我也要!! ContainerDNS
转自社区 ContainerDNS 本文介绍的 DNS 命名为 ContainerDNS,作为京东商城软件定义数据中心的关键基础服务之一,具有以下特点: 分布式,高可用 自动发现服务域名 后端探活 易 ...
- 【 PostgreSQL】工作中常用SQL语句干货
接触gp数据库近一年的时间,语法上和其他数据库还是有些许不同,工作中常用的操作语句分享给大家! -- 建表语句 create table ods.ods_b_bill_m ( acct_month t ...
- 消除 Xcode7 中 directory not found for option 'xxxx' 警告
消除 Xcode7 中 directory not found for option 'xxxx' 警告 升级Xcode7之后,你会遇到一些警告信息,诸如以下一条: ld: warning: dire ...
- 关于CATransform3D矩阵变换的简单解析
关于CATransform3D矩阵变换的简单解析 效果图: 我能能够用上的CATransform3D其实很简单,并不复杂. CATransform3D有着4种东西我们可以设置. 1. 透视效果(由m3 ...