P1202 [USACO1.1]黑色星期五Friday the Thirteenth

题目描述

13号又是一个星期五。13号在星期五比在其他日子少吗?为了回答这个问题,写一个程序,要求计算每个月的十三号落在周一到周日的次数。给出N年的一个周期,要求计算1900年1月1日至1900+N-1年12月31日中十三号落在周一到周日的次数,N为正整数且不大于400.

这里有一些你要知道的:

1、1900年1月1日是星期一.

2、4,6,11和9月有30天.其他月份除了2月都有31天.闰年2月有29天,平年2月有28天.

3、年份可以被4整除的为闰年(1992=4*498 所以 1992年是闰年,但是1990年不是闰年).

4、以上规则不适合于世纪年。可以被400整除的世纪年为闰年,否则为平年。所以,1700,1800,1900和2100年是平年,而2000年是闰年.

请不要调用现成的函数

请不要预先算好数据(就是叫不准打表)!

输入输出格式

输入格式:

 

一个正整数n.

 

输出格式:

 

输入输出样例

输入样例#1:
20
输出样例#1:
36 33 34 33 35 35 34

说明

题目翻译来自NOCOW。

USACO Training Section 1.1

复制代码
#include <cstdio>
#include <ctype.h>
#include <string>
#include <iostream>
#include <cstring>
#include <math.h>
#include <vector>
#include <queue>
#include <cstdio>
#include <iostream>
#include <cstring> 
using namespace std;
int year,last=1,go,ans[8];
int mouth[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int n;
void pass(int nowyear)
{    
    for(int i=1;i<=12;i++)
    {
        int t=0;
        if(i==2)
        {
            if(nowyear%100&&nowyear%4==0)
                t=1;else
            if(nowyear%400==0)    t=1;
        }
        go=(mouth[i]+t+last)%7;
        if(go==0)    last=7;else
        last=go;
        ans[last]++;
    }
}
int main()
{
    scanf("%d",&n);
    last=13%7;
    ans[last]++;
    for(int i=0;i<n;i++)
        pass(1900+i);
    ans[last]--;
    printf("%d ",ans[6]);
    printf("%d ",ans[7]);    
    for(int i=1;i<=5;i++)
        printf("%d ",ans[i]);
    return 0;
}
复制代码

 

posted @   浪矢-CL  阅读(443)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
· 【译】Visual Studio 中新的强大生产力特性
· 2025年我用 Compose 写了一个 Todo App
点击右上角即可分享
微信分享提示