Problem 19

You are given the following information, but you may prefer to do some research for yourself.
以下信息仅供参考(你可能会想自己去百度):
1 Jan 1900 was a Monday.  1900年一月一号是星期一
Thirty days has September, 九月、四月、六月以及十一月有30天
April, June and November.
All the rest have thirty-one, 其他月份有31天
Saving February alone, 二月份比较特殊
Which has twenty-eight, rain or shine. 闰年29天,平年28天
And on leap years, twenty-nine.
A leap year occurs on any year evenly divisible by 4, but not on a century unless it is divisible by 400.
闰年指可以被4整除的年份,但如果是世纪(如:1900)的话,需要能够整除400才算闰年
How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)?
二十世纪有多少个星期天在月份的第一天(从1901-01-01到2000-12-31)?
def leep_year(year):
if year % 100 == 0: # century
if year % 400 == 0:
return True
else:
if year % 4 == 0:
return True
return False week = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
month = {'January': 31, 'February': 28, 'March': 31, 'April': 30, 'May': 31, 'June': 30,
'July': 31, 'August': 31, 'September': 30, 'October': 31, 'November': 30, 'December': 31} count = 0
day = 'Monday' # 1900-01-01是星期一
index = 0
for year in range(1900, 2001):
if leep_year(year): # 闰年
month['February'] = 29
else: # 平年
month['February'] = 28
for m, d in month.items():
if day == 'Sunday':
count += 1
index = week.index(day) + d % 7
if index >= 7:
index %= 7
day = week[index]
if year == 1900: # 如果是1900年,归零(从1901-01-01到2000-12-31)
count = 0
print(count)
												

Problem 19的更多相关文章

  1. (Problem 19)Counting Sundays

    You are given the following information, but you may prefer to do some research for yourself. 1 Jan ...

  2. Common Bugs in C Programming

    There are some Common Bugs in C Programming. Most of the contents are directly from or modified from ...

  3. B. Checkout Assistant 01背包变形

    http://codeforces.com/problemset/problem/19/B 对于每个物品,能偷多ti个,那么先让ti + 1, 表示选了这个东西后,其实就是选了ti + 1个了.那么只 ...

  4. The Brain as a Universal Learning Machine

    The Brain as a Universal Learning Machine This article presents an emerging architectural hypothesis ...

  5. 【BFS】Tester Program

    [poj1024]Tester Program Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2760   Accepted ...

  6. softmax实现(程序逐句讲解)

    上一个博客已经讲了softmax理论部分,接下来我们就来做个实验,我们有一些手写字体图片(28*28),训练样本(train-images.idx3-ubyte里面的图像对应train-labels. ...

  7. [NOIP 2014] 寻找道路

    [题目链接] http://uoj.ac/problem/19 [算法] 首先,在反向图上从终点广搜,求出每个点是否可以在答案路径中 然后在正向图中求出源点至终点的最短路,同样可以使用广搜 时间复杂度 ...

  8. Python练习题 046:Project Euler 019:每月1日是星期天

    本题来自 Project Euler 第19题:https://projecteuler.net/problem=19 ''' How many Sundays fell on the first o ...

  9. 《DSP using MATLAB》Problem 5.19

    代码: function [X1k, X2k] = real2dft(x1, x2, N) %% --------------------------------------------------- ...

随机推荐

  1. 读书笔记-HBase in Action-第一部分 HBase fundamentals

    新项目准备上HBase.HBase眼下由组里某牛负责.本着学会使用HBase的目标,先阅读下HBase in Action,一共十章组织成三部分,须要学习的内容包含HBase基本实现原理,用法,Sch ...

  2. Python帮助函数调试函数 用于获取对象的属性及属性值

    Python帮助函数调试函数 用于获取对象的属性及属性值 刚接触Python,上篇 <Python入门>第一个Python Web程序--简单的Web服务器 中调试非常不方便,不知道对象详 ...

  3. Android 线程 Looper.prepare()、Looper.loop() 使用

    优化项目过程中发现了一个非常Low的问题,整理一下.备忘: 说问题之前先看下HandlerThread的定义 一个封装了looper的线程:   Looper用于封装了android线程中的消息循环. ...

  4. caioj1495: [视频]基于连通性状态压缩的 动态规划问题:Formula 2

    本来想写一天插头的,但是这题太难受(绝望)500+的代码量..我选择下午放松一下. 先ORZ一下苏大佬(yz的cdq啊%%%%%)居然把cdq论文里面的题抠出来出数据放在c站(呵呵真是个悲伤的故事不过 ...

  5. fixed和absolute

    fixed是相对于浏览器窗口固定 absolute是相对于整体网页固定.(整体网页包括所有的内容,包含右侧滑动条滑动所能看到的内容)

  6. 第13课 SmartGit程序操作介绍

    http://www.syntevo.com/

  7. PCB MVC启动顺序与各层之间数据传递对象关系

    准备着手基于MVC模式写一套Web端流程指示查看,先着手开发WebAPI打通数据接口,后续可扩展手机端 这里将MVC基本关系整理如下: 一.MVC启动顺序 二.MVC各层之间数据传递对象关系

  8. Django day16 Auth组件

    一:Auth组件 -django内置的用户认证系统,可以快速的实现,登录,注销,修改密码... -怎么用? (1)先创建超级用户: -python3 manage.py createsuperuser ...

  9. jmeter 参数化学习笔记

    上次写了在接口的交互过程中,系统返回的内容,需要在接下来的交互中用到,从而把参数进行参数化的关联,这次写一下在压测过程中,如果每次发起请求参数名相同,单参数值需要替换的,我们需要进行的参数化. 在使用 ...

  10. BZOJ 4517 组合数+错排

    思路: 预处理错排 然后C(n,m)*s[n-m-1]就是答案了 特判n-m-1<0 //By SiriusRen #include <cstdio> using namespace ...