usaco Friday the Thirteenth

/*
ID: modengd1
PROG: friday
LANG: C++
*/
#include <iostream>
#include <stdio.h>
#include <memory.h>
using namespace std;
int days[12]={31,29,31,30,31,30,31,31,30,31,30,31};
int N;
int counter[7];
bool isleap(int x)
{
    if((x%4)==0&&(x%100)!=0||((x%400)==0))
        return true;
    return false;
}
int main()
{
    freopen("friday.in","r",stdin);
    freopen("friday.out","w",stdout);
    scanf("%d",&N);
    memset(counter,0,sizeof(counter));
    long long day=1;
    for(int i=0;i<N;i++)
    {
        if(isleap(1900+i))
        {
            days[1]=29;
        }
        else
            days[1]=28;
        for(int j=0;j<12;j++)
        {
            counter[(day+13)%7]++;
            day+=days[j];
        }
    }
    cout<<counter[0];
    for(int i=1;i<7;i++)
        cout<<‘ ‘<<counter[i];
    putchar(‘\n‘);
    return 0;
}

  

时间: 2024-08-07 08:39:36

usaco Friday the Thirteenth的相关文章

USACO Section 1.1-3 Friday the Thirteenth

Friday the Thirteenth 黑色星期五 13号又是一个星期五.13号在星期五比在其他日子少吗?为了回答这个问题,写一个程序,要求计算每个月的十三号落在周一到周日的次数. 给出N年的一个周期,要求计算1900年1月1日至1900+N-1年12月31日中十三号落在周一到周日的次数,N为正整数且不大于400. 注意,开始今年是一千九百年,不是1990 这里有一些你要知道的: 1.1900年1月1日是星期一. 2.4,6,11和9月有30天.其他月份除了2月都有31天.闰年2月有29天,

USACO 1.1 Friday the Thirteenth

Friday the Thirteenth Is Friday the 13th really an unusual event? That is, does the 13th of the month land on a Friday less often than on any other day of the week? To answer this question, write a program that will compute the frequency that the 13t

USACO。s1.1.3Friday the Thirteenth(数组)

题意:计算n年里的12 * n个月里,每个月的13号落在周日到周六的次数. 思路&易错点:两个数组,一个数组1代表月份,一个数组2代表星期几,天数 % 7作为数组2的下标,自增.判断是否为闰年.某年的1月1号是周m,下一年的1月1号是周m + 1(闰年的话就m + 2,这个是开始时错了,找了几百年bug),就可以得到下一年的1月1号代表周几,继续mod. 代码如下: /* TASK:friday LANG:C++ ID:huibaochen */ #include <iostream>

USACO Section1.1 Friday the Thirteenth 解题报告

friday解题报告 —— icedream61 博客园(转载请注明出处) ------------------------------------------------------------------------------------------------------------------------------------------------[题目] 据说曾经的黑色星期五是13号?本题让我们看看13号与星期五是否比与别的日子更有缘. 给出非负数n,请告诉我在“1900年1月1

USACO Chapter 1 Section 1.1

USACO的题解和翻译已经很多了... 我只是把自己刷的代码保存一下. 1.PROB Your Ride Is Here 1 /* 2 ID:xiekeyi1 3 PROG:ride 4 LANG:C++ 5 */ 6 7 #include<bits/stdc++.h> 8 using namespace std ; 9 10 int main() 11 { 12 freopen("ride.in","r",stdin); 13 freopen(&quo

COGS 696. [IOI1996][USACO 2.3] 最长前缀

★   输入文件:prefix.in   输出文件:prefix.out   简单对比时间限制:1 s   内存限制:128 MB 描述 USACO 2.3.1 IOI96 在生物学中,一些生物的结构是用包含其要素的大写字母序列来表示的.生物学家对于把长的序列分解成较短的序列(即元素)很感兴趣. 如果一个集合 P 中的元素可以通过串联(元素可以重复使用,相当于 Pascal 中的 “+” 运算符)组成一个序列 S ,那么我们认为序列 S 可以分解为 P 中的元素.元素不一定要全部出现(如下例中B

USACO prefix TrieTree + DP

/* ID:kevin_s1 PROG:prefix LANG:C++ */ #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <vector> #include <map> #include <set> #include <algorithm> #include <cstdlib>

【USACO 1.3.4】牛式

[題目描述 ] 下面是一个乘法竖式,如果用我们给定的那n个数字来取代*,可以使式子成立的话,我们就叫这个式子牛式. * * * x * * ---------- * * * * * * ---------- * * * * 数字只能取代*,当然第一位不能为0,况且给定的数字里不包括0. 注意一下在美国的学校中教的"部分乘积",第一部分乘积是第二个数的个位和第一个数的积,第二部分乘积是第二个数的十位和第一个数的乘积. 写一个程序找出所有的牛式. [格式] INPUT FORMAT: (f

USACO Your Ride Is Here

[USACO]Your Ride Is Here It is a well-known fact that behind every good comet is a UFO. These UFOs often come to collect loyal supporters from here on Earth. Unfortunately, they only have room to pick up one group of followers on each trip. They do,