USACO Friday the Thirteenth
来源:互联网 发布:高级软件项目经理证书 编辑:程序博客网 时间:2024/05/25 23:57
1. 蔡勒公式:
来自百度百科
w:星期; w对7取模得:0-星期日,1-星期一,2-星期二,3-星期三,4-星期四,5-星期五,6-星期六
c:世纪(前两位数) 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余5,注意对负数的取模运算!)2. 取余运算:
请参考c语言的取模运算 - 迎宾的专栏 - 博客频道 - CSDN.NET
/*ID: dollarzhaolePROG: fridayLANG: C++*/#include <iostream>#include <fstream>#include <string>#include <cstring>using namespace std;int week[8];int getweek(int c, int y, int m, int d){ int w = y + y / 4 + c / 4 - 2 * c + 26 * (m + 1) / 10 + d - 1; return w;}int main(){ ofstream fout ("friday.out"); ifstream fin ("friday.in"); int n, tmp, year, month, i ,j; memset(week, 0, sizeof(week)); fin >> n; for (i = 0; i < n; i++) for (j = 1; j <= 12; j++) { year = i; month = j; if (j < 3) { year -= 1; month += 12; } tmp = getweek((1900 + year) / 100, (1900 + year) % 100, month, 13) % 7; if (tmp < 0) tmp += 7; week[tmp]++; } fout << week[6] << ' '; for (i = 0; i < 5; i++) fout << week[i] << ' '; fout << week[5] << endl; return 0;}
- Friday the Thirteenth(USACO)
- usaco--Friday the Thirteenth
- [USACO] Friday the Thirteenth
- usaco Friday the Thirteenth
- USACO Friday the Thirteenth
- USACO:Friday the Thirteenth
- USACO -Friday the Thirteenth
- USACO Friday the Thirteenth
- USACO Friday the Thirteenth
- USACO--Friday the Thirteenth
- usaco Friday the Thirteenth
- usaco Friday the Thirteenth
- usaco Friday the Thirteenth
- USACO 1.1-Friday the Thirteenth
- usaco 1.1:Friday the Thirteenth
- USACO 1.1 Friday the Thirteenth
- USACO之Friday the Thirteenth
- 【USACO】PROB Friday the Thirteenth
- java连接mysql
- 排序算法
- 对C#中float,double,decimal的理解
- Linux中安装Tomcat指定JDK
- Sharepoint试用(1)
- USACO Friday the Thirteenth
- 纯CSS定位的固定浮动层代码 不闪 兼容IE6 8 火狐 谷歌等
- 常用ios下高效的开源类库
- Windows7 密码轻松破解
- 设计为王的时代 创业公司如何解决设计师问题
- 6.Android MenuInflater的使用
- 设计模式5-原型模式
- [ACM实验]C++STL泛型编程
- Android系统服务-WindowManager