USACO 1.1 Friday 日期问题
来源:互联网 发布:淘宝直通车协议 编辑:程序博客网 时间:2024/04/26 00:46
题意概述:
统计每个月十三号在周几出现的次数,依次输出。
解题思路:
简单的日期计算问题,利用周几计算公式可以更方便地计算。具体公式如下:
d:日
m:月
y:年
w:周几
if(m==1||m==2)
{m+=12;y–;}
w=d+2*m+3*(m+1)/5+y+y/4-y/100+y/400)%7
题解代码:
/*ID: tsing961PROG: fridayLANG: C++*/#include<bits/stdc++.h>using namespace std;int day[2][12]={31,28,31,30,31,30,31,31,30,31,30,31,31,29,31,30,31,30,31,31,30,31,30,31};int isleap(int y){ if(y%4==0&&y%100!=0||y%400==0)return 1; return 0;}int main(){ int n; ofstream fout ("friday.out"); ifstream fin ("friday.in"); fin>>n; int a[7]={0}; for(int i=1900;i<1900+n;i++){ for(int j=1;j<=12;j++) for(int k=1;k<=day[isleap(i)][j-1];k++) if(k==13){ int y,m,d; y=i,m=j,d=k; if(m==1||m==2) { m+=12; y--; } a[(d+2*m+3*(m+1)/5+y+y/4-y/100+y/400)%7]++; } } fout<<a[5]<<" "<<a[6]<<" "; for(int i=0;i<=3;i++)fout<<a[i]<<" "; fout<<a[4]<<endl; return 0;}
阅读全文
1 0
- USACO 1.1 Friday 日期问题
- USACO 1.1 friday
- USACO 1.1 friday
- USACO--1.1friday
- USACO 1.1 friday
- usaco 1.1.3 friday
- USACO 1.1.3 Friday the Thirteenth (friday)
- USACO 1.1 Friday the Thirteenth (friday)
- USACO-Section1.1 Friday the Thirteenth [日期]
- USACO-Section1.1 Friday the Thirteenth [日期]
- USACO-Section1.1 Friday the Thirteenth[日期]
- USACO 1.1-Friday the Thirteenth
- usaco 1.1:Friday the Thirteenth
- USACO 1.1 Friday the Thirteenth
- usaco/1.1 Friday the Thirteenth
- USACO 1.1 Friday the Thirteenth
- USACO 1.1 Friday the Thirteenth
- USACO 1.1 Friday the Thirteenth
- Oracle服务与配置
- Python iter函数详解
- 设计模式-singletion
- spring的IOC 容器管理 Bean
- XML
- USACO 1.1 Friday 日期问题
- 两个单链表(无环)的公共节点问题
- SVM
- 数据库连接池
- 读 Zepto 源码之集合元素查找
- <fmt:formatNumber>标签
- github的简单使用及创建网页的方法
- 简书短篇小说专栏爬取
- XML解析