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 ...
随机推荐
- Python Djan 路由对应的名称
路由关系命名 对URL路由关系进行命名,以后可以根据此名称生成自己想要的URL 1. url(r'fdsafdsaeeeee',views.index, name='hello') #给这个url后面 ...
- UNIX 网络编程笔记-CH2:TCP、UDP概貌
好久不读不用又忘得差不多了,还是感叹Richard Stevens真是太刁,25年前第一版. "Tcp state diagram fixed new" by Scil100. L ...
- 关于mysql的 sql_mode=only_full_group_by 报错
在mysql中执行 : SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY','')); 官网:https://dev ...
- csharp:Conversion Between DataTable and List
/// <summary> /// http://www.codeproject.com/Tips/784090/Conversion-Between-DataTable-and-List ...
- drupal7 转化 public:// 为实际url
file_create_url('public://xxx.png'); // 得到URL drupal_realpath('public://xxx.png'); // 得到系统路径(磁盘路径,如D ...
- 3d图片点击切换
效果图: 代码块: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> < ...
- 关于modelmap.addAttribute("",)转到jsp页面获取不到值的问题
问题一,可能是你设置的web.xml的头有问题 掉坑里好一会,发现我默认生成的web.xml中头部的配置是 <!DOCTYPE web-app PUBLIC "-//Sun Micro ...
- RocketMQ读书笔记7——吞吐量优先的场景
[Broker端进行消息过滤] 在Broker端进行消息过滤,可以减少无效消息发送到Consumer,少占用网络宽带从而提高吞吐量. [过滤方式1——通过Tag过滤] [ 关于Tag和Key ] 对一 ...
- arcgis for js/flex/sl 该选哪一个?
arcgis server开发webgis 在客户端有3种选择:js.flex.sl 他们除了开发arcgis外,本身还有一些常用的领域 js:在传统网站中很常用 flex:游戏.视频播放.动画特效 ...
- Java Basis
java中.java源文件放在src文件夹下,.class文件放在bin文件夹下. java代码区域,以及控制台区域字体大小更改.Java->Java Editor Text Font ...