Problem 28

https://projecteuler.net/problem=28

Starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral is formed as follows:

从1开始,顺时针旋螺转,可得一个5*5的螺旋如下:

21 22 23 24 25
20  7  8  9 10
19  6  1  2 11
18  5  4  3 12
17 16 15 14 13

It can be verified that the sum of the numbers on the diagonals is 101.

对角线上的数字(粗体)之和等于101。

What is the sum of the numbers on the diagonals in a 1001 by 1001 spiral formed in the same way?

一个类似的1001*1001的螺旋的对角线上的数字之和为多少?

from math import pow

row = 1001
matrix = row * row
tot = [1]
spiral = [i for i in range(2, matrix+1)]
spiral = spiral[::-1] # 倒序排列螺旋 interval = 1
count = 0
while True:
try:
for i in range(interval): # 每隔interval个数字,加入一个数字至tot列表
spiral.pop()
tot.append(spiral.pop())
count += 1
if count == 4: # 每加入四个数字,interval加二
interval += 2
count = 0
except:
break print(sum(tot), tot)

Problem 28的更多相关文章

  1. (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 ...

  2. 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 ...

  3. CF28D Don't fear, DravDe is kind 背包

    题目传送门:http://codeforces.com/problemset/problem/28/D 题意:给你$N$个物品,每个物品有其价格$P_i$,之前必须要买的物品价格和$L_i$,之后必须 ...

  4. Time Limit Exceeded 求逆序对数。

    /** 题目:Time Limit Exceeded 链接:https://oj.ejq.me/problem/28 题意:求逆序对数. 思路:树状数组求逆序对数.维护前面有多少个<=当前数的数 ...

  5. PID28 [Stupid]愚蠢的宠物

    题链:https://www.rqnoj.cn/problem/28 题目描述 背景 大家都知道,sheep有两只可爱的宠物(一只叫神牛,一只叫神菜).有一天,sheep带着两只宠物到狗狗家时,这两只 ...

  6. Levmar:Levenberg-Marquardt非线性最小二乘算法

    Levmar:Levenberg-Marquardt非线性最小二乘算法 eryar@163.com Abstract. Levmar is GPL native ANSI C implementati ...

  7. 【VS开发】设备控制台 (DevCon.exe) 示例

    设备控制台 (DevCon.exe) 示例 本部分提供以下设备控制台 (DevCon.exe) 命令的示例: DevCon HwIDs 示例 1:查找所有硬件 ID 示例 2:使用模式查找硬件 ID ...

  8. B. pSort

    题目链接: http://codeforces.com/problemset/problem/28/B 题意: 给一个n,原本有个1到n按顺序排列的序列,给一个序列问,在给一个数组,表示这个位置的数可 ...

  9. 《DSP using MATLAB》Problem 5.28

    昨晚手机在看X信的时候突然黑屏,开机重启都没反应,今天维修师傅说使用时间太长了,还是买个新的吧,心疼银子啊! 这里只放前两个小题的图. 代码: 1. %% ++++++++++++++++++++++ ...

随机推荐

  1. adb 命令模拟按键事件 【转】

    本文转载自:http://blog.sina.com.cn/s/blog_68f262210102vc1b.html 转自:http://blog.csdn.net/jlminghui/article ...

  2. 如何的退出无响应的 SSH 连接

    ~. 具体操作是Shift+-,然后松开按.. tips如果无效,可以先按下Enter,然后进行上面的操作.

  3. P3092 [USACO13NOV]没有找零No Change 状压dp

    这个题有点意思,其实不是特别难,但是不太好想...中间用二分找最大的可买长度就行了. 题干: 题目描述 Farmer John <= K <= ), each with value .., ...

  4. shell脚本-数组

    shell脚本-数组 数组 变量:存储单个元素的内存空间. 数组:存储多个元素的连续的内存空间,相当于多个变量的集合. 数组索引:编号从0开始,属于数值索引.索引可支持使用自定义的格式,而不仅是数值格 ...

  5. PCB javascript解析Gerber274X格式实现方法

    解析钻Gerber274X格式前首先得了解此格式,这样才能更好的解析呀. 一个Gerber274X里面包含的基本信息如下: 1.单位:公式mm,英制inch 2.省零方式:前省零,后省零 3.坐标方式 ...

  6. Decode the Strings

    http://acm.hdu.edu.cn/showproblem.php?pid=2371 题意:给出一个长度为n的字符串(标号为1~n),以及n个数代表字符串的变换规则,问该字符串是由哪个字符串按 ...

  7. Balanced Lineup(线段树)

    http://poj.org/problem?id=3264 题意:n个数,q个询问,输出[l,r]中最大值与最小值的差. #include <stdio.h> #include < ...

  8. [Apple开发者帐户帮助]九、参考(5)支持的功能(tvOS)

    tvOS应用程序可用的功能取决于您的程序成员身份. 能力 ADP 企业 Apple开发者 应用程序组 相关域名   背景模式 数据保护 游戏中心     游戏控制器 HomeKit iCloud:Cl ...

  9. JavaScript中.和[]有什么区别?

    .与[]都可以用于读取或修改对象属性. <script> var myData={ name:"Adam", weather:"sunny", }; ...

  10. 【转】Java 集合系列12之 TreeMap详细介绍(源码解析)和使用示例

    概要 这一章,我们对TreeMap进行学习.我们先对TreeMap有个整体认识,然后再学习它的源码,最后再通过实例来学会使用TreeMap.内容包括:第1部分 TreeMap介绍第2部分 TreeMa ...