USACO Friday the Thirteenth

      模拟吧~~~

/*
ID: xyl57681
PROG: friday
LANG: C++
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <fstream>
using namespace std;
long long a[8];
int year1[2][13]={{0,31,28,31,30,31,30,31,31,30,31,30,31},
				 {0,31,29,31,30,31,30,31,31,30,31,30,31}};
int solve(int year){
	if((year%4==0&&year%100!=0)||year%400==0)
		return 1;
	else
		return 0;
}
int main(){
	ifstream fin ("friday.in");
    <span style="white-space:pre">	</span>ofstream fout ("friday.out");
	int N;
	fin>>N;
	int year=1900;
	memset(a,0,sizeof(a));
	long long all_days=0;
	while(year!=1900+N){
		for(int i=0;i<=11;i++){
			a[(all_days+13)%7]++;
			all_days+=year1[solve(year)][i+1];
		}
		year++;
	}
	fout<<a[6]<<" "<<a[0]<<" "<<a[1]<<" "<<a[2]<<" "
	    <<a[3]<<" "<<a[4]<<" "<<a[5]<<endl;
}

        然后又发现这道题居然有公式~~~

·····

蔡勒公式

*蔡勒公式是一种计算任何一日属一星期中哪一日的算法,由蔡勒(Julius Christian Johannes Zeller)推算出。

蔡勒公式.png
公式都是基于公历的置闰规则来考虑。
公式中的符号含义如下:

  • w:星期
  • c:世纪(前两位数)
  • y:年(后两位数)
  • m:月(m 的取值范围为 3 至 14,即在蔡勒公式中,某年的 1、2月要看作上一年的 13、14月来计算,比如2003年1月1日要看作2002年的13月1日来计算)
  • d:日
  • [ ]:称作高斯符号,代表取整,即只要整数部份。
  • mod:‎‎同余‎(这里代表括号里的答案除以 7 后的余数)(请注意前面是负数取模的情况,取模只可以是正数)

若要计算的日期是在1582年10月4日或之前,公式则为
蔡勒公式 before 15821004.png
(因罗马教皇修改历法,把1582年10月4日的下一天改为1582年10月15日)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值