鱼C论坛

 找回密码
 立即注册
查看: 2410|回复: 2

题目173:使用最多100万块瓷砖可以形成多少不同的中空的正方形?

[复制链接]
发表于 2016-9-15 01:14:16 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
Using up to one million tiles how many different "hollow" square laminae can be formed?

We shall define a square lamina to be a square outline with a square "hole" so that the shape possesses vertical and horizontal symmetry. For example, using exactly thirty-two square tiles we can form two different square laminae:

p173_square_laminas.gif


With one-hundred tiles, and not necessarily using all of the tiles at one time, it is possible to form forty-one different square laminae.

Using up to one million tiles how many different square laminae can be formed?


题目:

我们定义一个正方形薄板为一个中间为正方形空洞的正方形外框。这个形状在水平和竖直方向上都是对称的。比如,用 32 块方形砖,我们可以得到如下两个不同的薄板。

p173_square_laminas.gif


如果有 100 块砖,而且不需要一次全部使用的话,我们可以形成 25 种不同的正方形薄板。

那么请问,如果使用不超过 100 万块瓷砖的话,可以形成多少种不同的薄板呢?

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2017-8-16 17:26:58 | 显示全部楼层
  1. from numba import jit
  2. import time
  3. @jit
  4. def solve():
  5.         c = 0
  6.         for a in range(3, 250002):
  7.                 for b in range(1, (a-1)//2+1):
  8.                         if 4*b*(a-b) <= 1000000:
  9.                                 c += 1
  10.                         else:
  11.                                 break
  12.         return c
  13. tt = time.time()
  14. print(solve())
  15. print(time.time()-tt)
复制代码

1572729
0.1520087718963623
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-2-13 17:17:53 | 显示全部楼层
本帖最后由 永恒的蓝色梦想 于 2021-2-13 20:51 编辑

C++ 3ms
  1. #include<iostream>
  2. #include<cmath>



  3. int main() {
  4.     using namespace std;
  5.     ios::sync_with_stdio(false);

  6.     constexpr unsigned int UPPER_BOUND = 1000000, MAX_N =  UPPER_BOUND / 4 + 1;
  7.     unsigned int n = 3, result = 0, temp = sqrt(UPPER_BOUND);


  8.     do {
  9.         result += (n - 3) >> 1;
  10.         result++;
  11.         n++;
  12.     } while (n <= temp);
  13.    
  14.    
  15.     do {
  16.         temp = ceil(sqrt((unsigned long long)n * n - UPPER_BOUND));
  17.         result += (n - temp - 2) >> 1;
  18.         result++;
  19.         n++;
  20.     } while (n <= MAX_N);


  21.     cout << result << endl;
  22.     return 0;
  23. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-20 02:09

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表