ZOJ 3326 An Awful Problem 神坑模拟

本文详细介绍了如何通过编程解决在给定时间区间内,只有质数日期和质数月份可以获得糖果的问题。通过遍历日期、判断年份、月份和日期是否为质数来计算总糖果数量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

点击打开链接

An Awful Problem

Time Limit: 1 Second      Memory Limit: 32768 KB

In order to encourage Hiqivenfin to study math, his mother gave him a sweet candy when the day of the month was a prime number.Hiqivenfin was happy with that.But several days later, his mother modified the rule so that he could get a candy only when the day of the month was a prime number and the month was also a prime number.He felt a bit upset because he could get fewer candies.What's worse, his mother changed the rule again and he had to answer a question before he could get a candy in those days.The question was that how many candies he could get in the given time interval.Hiqivenfin wanted to cry and asked you for help.He promised to give you half of a candy if you could help him to solve this problem.

Input

There are multiple test cases.The first line of input is an integer T (0 <T <= 50), indicating the number of test cases. ThenT test cases follow. Thei-th line of the next T lines contains two dates, the day interval of the question. The format of the date is "yyyy mm dd". You can assume both dates are valid. Hiqivenfin was born at 1000-01-01 and would not die after 2999-12-31, so the queries are all in this interval.

Hiqivenfin didn't seem to be an earthman, but the calendar was the same as that we usually use.That is to say, you need to identify leap years, where February has 29 days. In the Gregorian calendar, leap years occur in years exactly divisible by four. So, 1993, 1994, and 1995 are not leap years, while 1992 and 1996 are leap years. Additionally, the years ending with 00 are leap years only if they are divisible by 400. So, 1700, 1800, 1900, 2100, and 2200 are not leap years, while 1600, 2000, and 2400 are leap years.

Output

Output the number of candies Hiqivenfin could get in the time interval. Both sides of the interval are inclusive.

Sample Input

2
1000 01 01 1000 01 31
2000 02 01 2000 03 01

Sample Output

0
10

Author: GUAN, Yao
Source: The 7th Zhejiang Provincial Collegiate Programming Contest

交了11次,WA了11次,各种测试数据各种过,检查了一遍又一遍,代码都很完美,有史以来,最坑爹的模拟找我碰上了,附上zeh挫折码,谁能帮我AC了,以身相娶也不难。

#include<stdio.h>
int main()
{
    int tt;
    //freopen("in.txt","r",stdin);
    scanf("%d",&tt);
    while(tt--)
    {
        int y1,m1,d1,y2,m2,d2,ans=0;
        scanf("%d%d%d%d%d%d",&y1,&m1,&d1,&y2,&m2,&d2);

        if(y2-y1>=2)//求年的天数
        {
            for(int i=y1+1; i<=y2-1; i++)
                if((i%4==0&&i%100!=0)||i%400==0)
                    ans+=53;
                else ans+=52;
        }
        //printf("年==%d\n",ans);
        if(y1<y2)//如果不再同一年
        {
            for(int i=m1+1; i<=11; i++)//开始日期的月数
            {
                if(i==2)
                {
                    if((y1%4==0&&y1%100!=0)||y1%400==0)
                        ans+=10;
                    else ans+=9;
                }
                else if(i==3||i==5||i==7)
                    ans+=11;
                else if(i==11)
                    ans+=10;
            }
            for(int i=2;i<=m2-1;i++)//结束日期的月数
            {
                if(i==2)
                {
                    if((y2%4==0&&y2%100!=0)||y2%400==0)
                        ans+=10;
                    else ans+=9;
                }
                else if(i==3||i==5||i==7)
                    ans+=11;
                else if(i==11)
                    ans+=10;
            }
        }
        else if(y1==y2)//如果在同一年求月数
        {
            if((m2-m1)>=1)
            {
                for(int i=m1+1; i<=m2-1; i++)
                {
                    if(i==2)
                    {
                        if((y2%4==0&&y2%100!=0)||y2%400==0)
                            ans+=10;
                        else ans+=9;
                    }
                    else if(i==3||i==5||i==7)
                        ans+=11;
                    else if(i==11)
                        ans+=10;
                }
            }
            //printf("第二个书的月%d\n",ans);
        }
        int t;
        if(m1==3||m1==5||m1==7)
            t=31;
        else if(m1==11)
            t=30;
        else if(m1==2)
        {
            if((y1%4==0&&y1%100!=0)||y1%400==0)
                t=29;
            else t=28;
        }
        else t=0;
        if(m1==m2)
        {
            if(m1==2||m1==3||m1==5||m1==7||m1==11)
            {
                for(int i=d1; i<=d2; i++)
                    if(i==2||i==3||i==5||i==7||i==11||i==13||i==17||i==19||i==23||i==29||i==31)
                        ans++;
            }
            printf("%d\n",ans);
        }
        else
        {
            if(m1==2||m1==3||m1==5||m1==7||m1==11)
            {
                for(int i=d1; i<=t; i++)
                    if(i==2||i==3||i==5||i==7||i==11||i==13||i==17||i==19||i==23||i==29||i==31)
                        ans++;
            }
            //printf("第1次的天书%d\n",ans);
            if(m2==2||m2==3||m2==5||m2==7||m2==11)
            {
                for(int i=2; i<=d2; i++)
                    if(i==2||i==3||i==5||i==7||i==11||i==13||i==17||i==19||i==23||i==29||i==31)
                        ans++;
            }
            //printf("第二次的天书%d\n",ans);
            printf("%d\n",ans);
        }
        //printf("第一个数的月=%d\n",ans);
    }
    return 0;
}



内容概要:本文档详细介绍了Analog Devices公司生产的AD8436真均方根-直流(RMS-to-DC)转换器的技术细节及其应用场景。AD8436由三个独立模块构成:轨到轨FET输入放大器、高动态范围均方根计算内核和精密轨到轨输出放大器。该器件不仅体积小巧、功耗低,而且具有广泛的输入电压范围和快速响应特性。文档涵盖了AD8436的工作原理、配置选项、外部组件选择(如电容)、增益调节、单电源供电、电流互感器配置、接地故障检测、三相电源监测等方面的内容。此外,还特别强调了PCB设计注意事项和误差源分析,旨在帮助工程师更好地理解和应用这款高性能的RMS-DC转换器。 适合人群:从事模拟电路设计的专业工程师和技术人员,尤其是那些需要精确测量交流电信号均方根值的应用开发者。 使用场景及目标:①用于工业自动化、医疗设备、电力监控等领域,实现对交流电压或电流的精准测量;②适用于手持式数字万用表及其他便携式仪器仪表,提供高效的单电源解决方案;③在电流互感器配置中,用于检测微小的电流变化,保障电气安全;④应用于三相电力系统监控,优化建立时间和转换精度。 其他说明:为了确保最佳性能,文档推荐使用高质量的电容器件,并给出了详细的PCB布局指导。同时提醒用户关注电介质吸收和泄漏电流等因素对测量准确性的影响。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值