编程之美2015资格赛

题目1 : 2月29日

时间限制: 2000ms
单点时限: 1000ms
内存限制: 256MB

描述

给定两个日期,计算这两个日期之间有多少个2月29日(包括起始日期)。

只有闰年有2月29日,满足以下一个条件的年份为闰年:

1. 年份能被4整除但不能被100整除

2. 年份能被400整除

输入

第一行为一个整数T,表示数据组数。

之后每组数据包含两行。每一行格式为"month day, year",表示一个日期。month为{"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November" , "December"}中的一个字符串。day与year为两个数字。

数据保证给定的日期合法且第一个日期早于或等于第二个日期。

输出

对于每组数据输出一行,形如"Case #X: Y"。X为数据组数,从1开始,Y为答案。

数据范围

1 ≤ T ≤ 550

小数据:

2000 ≤ year ≤ 3000

大数据:

2000 ≤ year ≤ 2×109

样例输入
4
January 12, 2012
March 19, 2012
August 12, 2899
August 12, 2901
August 12, 2000
August 12, 2005
February 29, 2004
February 29, 2012
样例输出
Case #1: 1
Case #2: 0
Case #3: 1
Case #4: 3
//注意细节就ok了
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;

int t,date1,year1,date2,year2;
char month1[50],month2[50];
char a;

int judgeMonth(char month[]){
    if(month[0] == 'F') return 2;
    else if(month[0] == 'S') return 9;
    else if(month[0] == 'O') return 10;
    else if(month[0] == 'N') return 11;
    else if(month[0] == 'D') return 12;
    else if(month[0] == 'J'){
        if(month[1] == 'a') return 1;
        else{
            if(month[2] == 'n') return 6;
            else return 7;
        }
    }
    else if(month[0] == 'M'){
        if(month[2] == 'y' ) return 5;
        else return 3;
    }
    else{
        if(month[1] == 'u') return 8;
        else return 4;
    }
}

bool judgeYear( int year ){
    if(year % 4 != 0) return false;
    else if(year % 100 != 0) return true;
    else if(year % 400 != 0) return false;
    else return true;
}

int cmpDate( int m1, int d1, int m2, int d2){
    if(m1 > m2) return 1;
    else if(m1 == m2){
        if(d1 > d2) return 1;
        else if(d1 == d2) return 0;
        else return -1;
    }
    else return -1;
}

int main(){
    scanf("%d",&t);
    for(int item = 1; item <= t; item ++){
        cin.get();
        scanf("%s",month1);
        scanf("%d",&date1);
        cin.get();
        scanf("%c",&a);
        scanf("%d",&year1);

        cin.get();
        scanf("%s",month2);
        scanf("%d",&date2);
        cin.get();
        scanf("%c",&a);
        scanf("%d",&year2);

        int m1 = judgeMonth(month1);
        int m2 = judgeMonth(month2);

        int ans = 0;

        if(year1 == year2){
            if(!judgeYear(year1)) ans = 0;
            else{
                if(cmpDate(m1,date1,2,29) <= 0 && cmpDate(m2,date2,2,29) >= 0)
                    ans = 1;
                else
                    ans = 0;
            }
        }
        else if(year1 == year2 - 1){
            if(judgeYear(year1) && cmpDate(m1,date1,2,29) <= 0) ans ++;
            if(judgeYear(year2) && cmpDate(m2,date2,2,29) >= 0) ans ++;
        }
        else{
            if(judgeYear(year1) && cmpDate(m1,date1,2,29) <= 0) ans ++;
            if(judgeYear(year2) && cmpDate(m2,date2,2,29) >= 0) ans ++;

            year1 ++;
            year2 --;
            while(year1 % 4 != 0) year1 ++;
            while(year2 % 4 != 0) year2 --;

            if(year1 <= year2){
                while(year1 <= year2 && year1 % 100 != 0){
                    ans ++;
                    year1 += 4;
                }

                if(year1 % 400 != 0){
                    while(year1 + 100 <= year2){
                        ans = ans + 24;
                        year1 += 100;
                        if(year1 % 400 == 0) break;
                    }
                }

                while(year1 + 400 <= year2){
                    ans = ans + 97;
                    year1 += 400;
                }

                if(year1 <= year2 && judgeYear(year1)) ans++;

                while(year1 + 100 <= year2){
                    ans = ans + 24;
                    year1 += 100;
                }

                while(year1 + 4 <= year2){
                    ans++;
                    year1 += 4;
                }
            }
        }

        printf("Case #%d: %d\n",item, ans);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
目标检测(Object Detection)是计算机视觉领域的一个核心问,其主要任务是找出图像中所有感兴趣的目标(物体),并确定它们的类别和位置。以下是对目标检测的详细阐述: 一、基本概念 目标检测的任务是解决“在哪里?是什么?”的问,即定位出图像中目标的位置并识别出目标的类别。由于各类物体具有不同的外观、形状和姿态,加上成像时光照、遮挡等因素的干扰,目标检测一直是计算机视觉领域最具挑战性的任务之一。 二、核心问 目标检测涉及以下几个核心问: 分类问:判断图像中的目标属于哪个类别。 定位问:确定目标在图像中的具体位置。 大小问:目标可能具有不同的大小。 形状问:目标可能具有不同的形状。 三、算法分类 基于深度学习的目标检测算法主要分为两大类: Two-stage算法:先进行区域生成(Region Proposal),生成有可能包含待检物体的预选框(Region Proposal),再通过卷积神经网络进行样本分类。常见的Two-stage算法包括R-CNN、Fast R-CNN、Faster R-CNN等。 One-stage算法:不用生成区域提议,直接在网络中提取特征来预测物体分类和位置。常见的One-stage算法包括YOLO系列(YOLOv1、YOLOv2、YOLOv3、YOLOv4、YOLOv5等)、SSD和RetinaNet等。 四、算法原理 以YOLO系列为例,YOLO将目标检测视为回归问,将输入图像一次性划分为多个区域,直接在输出层预测边界框和类别概率。YOLO采用卷积网络来提取特征,使用全连接层来得到预测值。其网络结构通常包含多个卷积层和全连接层,通过卷积层提取图像特征,通过全连接层输出预测结果。 五、应用领域 目标检测技术已经广泛应用于各个领域,为人们的生活带来了极大的便利。以下是一些主要的应用领域: 安全监控:在商场、银行
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值