1648 Bovine Birthday【解题报告-蔡勒公式】

来源:互联网 发布:stl源码剖析 pdf 目录 编辑:程序博客网 时间:2024/05/16 17:23

 

Bovine Birthday
时间限制(普通/Java):1000MS/10000MS     运行内存限制:65536KByte
总提交: 9            测试通过: 5


http://acm.tzc.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=1648

描述:

Bessie asked her friend what day of the week she was born on. She knew that she was born on 2003 May 25, but didn't know what day it was. Write a program to help. Note that no cow was born earlier than the year 1800.

Facts to know:

* January 1, 1900 was on a Monday.

* Lengths of months:
    Jan 31          May 31      Sep 30
Feb 28 or 29 Jun 30 Oct 31
Mar 31 Jul 31 Nov 30
Apr 30 Aug 31 Dec 31

* Every year evenly divisible by 4 is a leap year (1992 = 4*498 so 1992 will be a leap year, but the year 1990 is not a leap year).

* The rule above does not hold for century years. Century years divisible by 400 are leap years, all other are not. Thus, the century years 1700, 1800, 1900 and 2100 are not leap years, but 2000 is a leap year.

 

输入

* Line 1: Three space-separated integers that represent respectively the year, month (range 1..12), and day of a date.

 

输出

* Line 1: A single word that is the day of the week of the specified date (from the lower-case list: monday, tuesday, wednesday, thursday, friday, saturday, sunday).

 

样例输入

 

2003 5 25

 

样例输出

 

sunday

 

提示

INPUT DETAILS:
May 25, 2003

OUTPUT DETAILS:

      May 2003
Su Mo Tu We Th Fr Sa
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

 

 

运用的公式:

/*
     蔡勒公式如下:
  W = [C/4] - 2C + y + [y/4] + [13 * (M+1) / 5] + d - 1
  或者是:w=y+[y/4]+[c/4]-2c+[26(m+1)/10]+d-1
  公式中的符号含义如下:
  w:星期; w对7取模得:0-星期日,1-星期一,2-星期二,3-星期三,4-星期四,5-星期五,6-星期六
  c:世纪-1(前两位数)//其实这里就是年份的前两位
  y:年(后两位数)
  m:月(m大于等于3,小于等于14,即在蔡勒公式中,某年的1、2月要看作上一年的13、14月来计算,比如2003年1月1日要看作2002年的13月1日来计算
  d:日
  [ ]代表取整,即只要整数部分。
  下面以中华人民共和国成立100周年纪念日那天(2049年10月1日)来计算是星期几,过程如下: 
  w=y+[y/4]+[c/4]-2c+[26(m+1)/10]+d-1 
  =49+[49/4]+[20/4]-2×20+[26×(10+1)/10]+1-1 
  =49+[12.25]+5-40+[28.6] 
  =49+12+5-40+28 
  =54 (除以7余5) 
  即2049年10月1日(100周年国庆)是星期五。
  再比如计算2006年4月4日,过程如下:
  w=y+[y/4]+[c/4]-2c+[26(m+1)/10]+d-1 
  =6+[6/4]+[20/4]-2*20+[26*(4+1)/10]+4-1
  =-12 (除以7余2,
注意对负数的取模运算!)

 


*/

非常好用但是要注意里面的两点。

 

 

代码:

 

原创粉丝点击