USACO 1.1 Friday the Thirteenth

[报告]

   本来这道题昨天就能AC了,但是由于此程序一交上去,USACO爆了。……

   实际上就是枚举,枚举每个月13日是星期几,再累加下就OK了。

   我的计算方法是:第1年先算出来,从第2年开始,星期?=(星期?+上月天数)%7,就可以了。

[程序](我删注释拉!)


#include <cstdlib>
#include <cstring>
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin ("friday.in");
ofstream fout ("friday.out");
long n;
long s[7];
inline void init()
{
       fin >> n;
}
inline long month(long y,long m)
{
       if ((y%400==0)||((y%4==0)&&(y%100!=0)))
          switch (m)
          {
                 case 1:return 31;
                 case 2:return 29;
                 case 3:return 31;
                 case 4:return 30;
                 case 5:return 31;
                 case 6:return 30;
                 case 7:return 31;
                 case 8:return 31;
                 case 9:return 30;
                 case 10:return 31;
                 case 11:return 30;
                 case 12:return 31;
          }
       else
          switch (m)

posted @ 2009-12-14 15:19  为美好世界献上珂学  阅读(93)  评论(0编辑  收藏  举报