Problem 28
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的更多相关文章
- (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 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 ...
- CF28D Don't fear, DravDe is kind 背包
题目传送门:http://codeforces.com/problemset/problem/28/D 题意:给你$N$个物品,每个物品有其价格$P_i$,之前必须要买的物品价格和$L_i$,之后必须 ...
- Time Limit Exceeded 求逆序对数。
/** 题目:Time Limit Exceeded 链接:https://oj.ejq.me/problem/28 题意:求逆序对数. 思路:树状数组求逆序对数.维护前面有多少个<=当前数的数 ...
- PID28 [Stupid]愚蠢的宠物
题链:https://www.rqnoj.cn/problem/28 题目描述 背景 大家都知道,sheep有两只可爱的宠物(一只叫神牛,一只叫神菜).有一天,sheep带着两只宠物到狗狗家时,这两只 ...
- Levmar:Levenberg-Marquardt非线性最小二乘算法
Levmar:Levenberg-Marquardt非线性最小二乘算法 eryar@163.com Abstract. Levmar is GPL native ANSI C implementati ...
- 【VS开发】设备控制台 (DevCon.exe) 示例
设备控制台 (DevCon.exe) 示例 本部分提供以下设备控制台 (DevCon.exe) 命令的示例: DevCon HwIDs 示例 1:查找所有硬件 ID 示例 2:使用模式查找硬件 ID ...
- B. pSort
题目链接: http://codeforces.com/problemset/problem/28/B 题意: 给一个n,原本有个1到n按顺序排列的序列,给一个序列问,在给一个数组,表示这个位置的数可 ...
- 《DSP using MATLAB》Problem 5.28
昨晚手机在看X信的时候突然黑屏,开机重启都没反应,今天维修师傅说使用时间太长了,还是买个新的吧,心疼银子啊! 这里只放前两个小题的图. 代码: 1. %% ++++++++++++++++++++++ ...
随机推荐
- 基于TCP/UDP的socket编程
基于TCP(面向连接)的socket编程服务器端顺序: 1. 创建套接字(socket) 2. 将套接字绑定到一个本地地址和端口上(bind) 3. 将套接字设为监听模式,准备接收客户请求(liste ...
- MyReport报表系统v1.2公布
经过多月奋战.MyReport报表系统最终完好,里程碑版本号V1.2隆重公布. 系统介绍 MyReport报表系统是基于MyReport报表引擎构建的报表开发工具平台产品.用户可以高速搭建报表中心,实 ...
- UVA1602 Lattice Animals 搜索+剪枝
题目大意 给出一个$w\times h$的网格,定义一个连通块为一个元素个数为$n$的方格的集合$A,\forall x\in A, \exists y\in A$,使得$x,y$有一条公共边.现要求 ...
- java多线程——线程通信
一.线程通信目标 1.线程通信的目标是使线程间能够互相发送信号 2.线程通信使线程能够等待其他线程的信号 二.几种方式 1.通过共享对象 2.忙等待 线程 B 运行在一个循环里,以等待信号 (不释放c ...
- Android之仿今日头条顶部导航栏效果
随着时间的推移现在的软件要求显示的内容越来越多,所以要在小的屏幕上能够更好的显示更多的内容,首先我们会想到底部菜单栏,但是有时候像今日头条新闻客户端要显示的内容太多,而且又想在主界面全部显示出来,所以 ...
- 第三周 Leetcode 4. Median of Two Sorted Arrays (HARD)
4. Median of Two Sorted Arrays 给定两个有序的整数序列.求中位数,要求复杂度为对数级别. 通常的思路,我们二分搜索中位数,对某个序列里的某个数 我们可以在对数时间内通过二 ...
- E20170617-hm
notation n. 记号,标记法; implicit adj. 不言明[含蓄]的; 无疑问的,绝对的; 成为一部份的; 内含的; selector n. 选择者,选择器; promot ...
- Magnetic Storms
http://acm.timus.ru/problem.aspx?space=1&num=1126 简单的线段树求区间最值 #include <stdio.h> #include ...
- 这里有最全的C/C++入门到进阶书籍推荐,你需要嘛?
编程是操作性很强的一门知识,看书少不了,但只有学习和实践相结合才能起到很好的效果,一种学习方法是看视频->看书->研究书中例子->自己做些东西->交流->看书. 研究经典 ...
- Spring Web MVC核心架构
可以查看DispatherServlet中的源代码,就是doDispatch()方法!