鱼C论坛

 找回密码
 立即注册
查看: 2027|回复: 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 万块瓷砖的话,可以形成多少种不同的薄板呢?

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2017-8-16 17:26:58 | 显示全部楼层
from numba import jit
import time
@jit
def solve():
        c = 0
        for a in range(3, 250002):
                for b in range(1, (a-1)//2+1):
                        if 4*b*(a-b) <= 1000000:
                                c += 1
                        else:
                                break
        return c
tt = time.time()
print(solve())
print(time.time()-tt)
1572729
0.1520087718963623
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

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

C++ 3ms
#include<iostream>
#include<cmath>
 


int main() {
    using namespace std;
    ios::sync_with_stdio(false);

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


    do {
        result += (n - 3) >> 1;
        result++;
        n++;
    } while (n <= temp);
    
    
    do {
        temp = ceil(sqrt((unsigned long long)n * n - UPPER_BOUND));
        result += (n - temp - 2) >> 1;
        result++;
        n++;
    } while (n <= MAX_N);


    cout << result << endl;
    return 0;
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-7-2 21:41

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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