Problem 19
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的更多相关文章
- (Problem 19)Counting Sundays
You are given the following information, but you may prefer to do some research for yourself. 1 Jan ...
- Common Bugs in C Programming
There are some Common Bugs in C Programming. Most of the contents are directly from or modified from ...
- B. Checkout Assistant 01背包变形
http://codeforces.com/problemset/problem/19/B 对于每个物品,能偷多ti个,那么先让ti + 1, 表示选了这个东西后,其实就是选了ti + 1个了.那么只 ...
- The Brain as a Universal Learning Machine
The Brain as a Universal Learning Machine This article presents an emerging architectural hypothesis ...
- 【BFS】Tester Program
[poj1024]Tester Program Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2760 Accepted ...
- softmax实现(程序逐句讲解)
上一个博客已经讲了softmax理论部分,接下来我们就来做个实验,我们有一些手写字体图片(28*28),训练样本(train-images.idx3-ubyte里面的图像对应train-labels. ...
- [NOIP 2014] 寻找道路
[题目链接] http://uoj.ac/problem/19 [算法] 首先,在反向图上从终点广搜,求出每个点是否可以在答案路径中 然后在正向图中求出源点至终点的最短路,同样可以使用广搜 时间复杂度 ...
- Python练习题 046:Project Euler 019:每月1日是星期天
本题来自 Project Euler 第19题:https://projecteuler.net/problem=19 ''' How many Sundays fell on the first o ...
- 《DSP using MATLAB》Problem 5.19
代码: function [X1k, X2k] = real2dft(x1, x2, N) %% --------------------------------------------------- ...
随机推荐
- HDU 5294 Tricks Device(多校2015 最大流+最短路啊)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5294 Problem Description Innocent Wu follows Dumb Zha ...
- 关于ffmpeg的安装具体步骤和说明
一.windows安装: 直接下载地址: https://ffmpeg.zeranoe.com/builds/ https://ffmpeg.zeranoe.com/builds/win64/stat ...
- IOS6.0自带下拉刷新控件UIRefreshControl
1.UIRefreshControl必需要在IOS6.0以后才干使用,同一时候他仅仅能在UITableViewController类中才干够使用 2.使用比較简单 self.refreshContro ...
- Codeforces--630K--Indivisibility(容斥)
K - Indivisibility Crawling in process... Crawling failed Time Limit:500MS Memory Limit:65536 ...
- Human Gene Functions(dp)
http://poj.org/problem?id=1080 #include <stdio.h> #include <stdlib.h> #include <strin ...
- Apache 虚拟主机 配置方法
打开httpd.conf文件 去掉LoadModule vhost_alias_module modules/mod_vhost_alias.so前面的#号 去掉Include conf/extra/ ...
- B - Lucky Division
Problem description Petya loves lucky numbers. Everybody knows that lucky numbers are positive integ ...
- 如何正确从windows系统(自己电脑)远程访问Linux系统(他人电脑)的mysql数据库(图文详解)
这里,需要Linux系统开了root用户,我这给root用户密码为root. 同时,在mysql -uroot -proot执行进去之后 update user setHost='%' whe ...
- oracle-3种工具使用
1:原命令行,dos 2:sqlplus,图形界面 3:isqlplus,网页版的.(假如自己机器无法安装oracle,可通过别人ip地址去使用oracle,http://ip:5560/isqlpl ...
- IN、EXISTS的相关子查询用INNER JOIN 代替--性能优化
如果保证子查询没有重复 ,IN.EXISTS的相关子查询可以用INNER JOIN 代替.比如: IN.EXISTS的相关子查询用INNER JOIN 代替--sql2000性能优化