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. 【Android】开发优化之——调优工具:TrackView,Method Profiling

    Android SDK自带的tool TrackView 位于 sdk的tools文件夹下.使用方法为:进入到tools下,执行 traceview e:\loginActivityTracing.t ...

  2. Android Back键和Home键的区别

    back键 Android的程序无需刻意的去退出,当你一按下手机的back键的时候,系统会默认调用程序栈中最上层Activity的Destroy()方法来,销毁当前Activity.当此Activit ...

  3. 针对深度学习(神经网络)的AI框架调研

    针对深度学习(神经网络)的AI框架调研 在我们的AI安全引擎中未来会使用深度学习(神经网络),后续将引入AI芯片,因此重点看了下业界AI芯片厂商和对应芯片的AI框架,包括Intel(MKL CPU). ...

  4. [AtCoder3954]Painting Machines

    https://www.zybuluo.com/ysner/note/1230961 题面 有\(n\)个物品和\(n-1\)台机器,第\(i\)台机器会为第\(i\)和\(i+1\)个物品染色.设有 ...

  5. poj3926

    dp+优化 很明显可以用单调队列优化. 记录下自己犯的sb错误:  数组开小,sum没搞清... #include<cstdio> #include<cstring> usin ...

  6. C语言实现字符串拼接

    #include <stdio.h>#include <stdlib.h>#include <string.h> char* str_contact(const c ...

  7. 手写DAO框架(一)-从“1”开始

    背景: 很久(4年)之前写了一个DAO框架-zxdata(https://github.com/shuimutong/zxdata),这是我写的第一个框架.因为没有使用文档,我现在如果要用的话,得从头 ...

  8. POJ 2342 Anniversiry Party(TYVJ1052 没有上司的舞会)

    题意: P1052 没有上司的舞会 描述 Ural大学有N个职员,编号为1~N.他们有从属关系,也就是说他们的关系就像一棵以校长为根的树,父结点就是子结点的直接上司.每个职员有一个快乐指数.现在有个周 ...

  9. Oracle 中文排序

        按照拼音顺序(常用)     ORDER BY nlssort(NAME, 'NLS_SORT=SCHINESE_PINYIN_M') 按照部首顺序 ORDER BY nlssort(NAME ...

  10. Struts2 在拦截器中向Action传参

    struts.xml配置文件: <package name="system-default" extends="struts-default" abstr ...