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

题目:
https://www.luogu.org/problem/show?pid=1202

在洛谷,这个题只有入门难度;
但我调了两个多小时;

主要原因在于我只是用gdb调试和用肉眼看;

而对于这种题,最好的调试方法是输出中间变量;

适当的标识汉字有利于调试;

我并不觉得做简单题是在消磨时间;

相反,A掉这道题,我很开心,甚至比做出理论上比这难几十倍的题后更开心;

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

int n,num,cnt[12];
int a[1001][13];
int ss=0;


bool pdnian(int x)
{
    if(!(x%100))
    {
        if(!(x%400)) return true;
        else return false;
    }
    else 
    {
        if(!(x%4)) return true;
        else return false;
    }
}

void ji(int x)
{
    int tot=x-1900;
    a[tot][4]=a[tot][6]=a[tot][9]=a[tot][11]=30;
    if(pdnian(x)) a[tot][2]=29;
    else a[tot][2]=28;
    a[tot][1]=a[tot][3]=a[tot][5]=a[tot][7]=a[tot][8]=a[tot][10]=a[tot][12]=31;
    return;
}

void solve()
{
    scanf("%d",&n);
    for(int i=1900;i<=1900+n-1;i++)
    {
         ji(i);
//       cout<<i<<"   ";
//       for(int j=1;j<=12;j++) cout<<a[i-1900][j]<<" ";
//       cout<<endl;

    } 
    //预处理出天数,及是否是闰年; 
    num=1;//第一天是星期一; 
    for(int i=1900;i<=1900+n-1;i++)
    {
        int x=i-1900;//获取当前的年数; 
        for(int j=1;j<=12;j++)
        {
            ss=a[x][j];
        //  cout<<"年份 :"<<i<<" 月份:"<<j<<" 第一天星期 :"<<num;
            int c=(num+12)%7;
            cnt[c]++;
            num=(num+ss)%7;
        //  cout<<"  十三号星期"<<c<<" 有"<<ss<<"天"<<endl;
        }
    }
    cout<<cnt[6]<<" ";
    for(int i=0;i<=5;i++) cout<<cnt[i]<<" ";
    return;
}

int main()
{
    solve();
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值