zoukankan      html  css  js  c++  java
  • hdu 6010 Daylight Saving Time 泰勒公式

    Daylight Saving Time

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)


    Problem Description
    Last month, xiaodao together with her friend poteko took a flight from San Francisco to Shanghai.
    When they were driving to the airport, xiaodao suddenly realized that the clock time on potekos car is one hour faster than the clock time on her mobile phone. And both of them might be correct, but how can it be? Because that day was Nov 6th, the Daylight saving time switch day this year.
    Daylight saving time (DST) or summer time is the practice of advancing clocks during summer months by one hour so that evening daylight lasts an hour longer. It is arguable that using DST can reduce overall energy consumption. Not all of us are using DST now, and for those regions adopting DST, the practices are also different.
    In the case of California, effective in the U.S. in 2007 as a result of the Energy Policy Act of 2005, the local time changes from Pacific Standard Time (PST) to Pacific Daylight Time (PDT) at 02:00 to 03:00 on the second Sunday in March and the local time changes back from PDT to PST at 02:00 to 01:00 on the first Sunday in November.
    Because it is one hour longer on that day, so xiaodao and poteko didn’t miss the flights, but they found it still a little confusing. Interestingly, once xiaodao went back to Shanghai, she met a bug caused by exactly the same issue during the work. You might also be in trouble with DST some day, so here comes this problem and hope it will be helpful.
    The local time in California without specifying whether it is PST or PDT could be ambiguous in some cases (e.g. 2016-11-06 01:25:00). In this problem, you are given a local time in California.
    Check whether it is “PST”, “PDT”, “Both” or “Neither”.
     
    Input
    The first line of the input gives the number of test cases, T.
    T test cases follow. Each test case consists of one line, a date string written in the following format: YYYY-MM-DD HH:MM:SS.
     
    Output
    For each test case, first output one line containing “Case #x: ”, where x is the test case number (starting from 1), following a result string which in one of “PST”, “PDT”, “Both” or “Neither”.
     1 ≤ T ≤ 1000.
     date will be legal and between “2007-01-01 00:00:00” and “2100-12-31 23:59:59”.
     
    Sample Input
    4 2016-03-13 01:59:59 2016-03-13 02:00:00 2016-11-06 00:59:59 2016-11-06 01:00:00
     
    Sample Output
    Case #1: PST Case #2: Neither Case #3: PDT Case #4: Both
     
    Source
     

    思路:泰勒公式;

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<string>
    #include<queue>
    #include<algorithm>
    #include<stack>
    #include<cstring>
    #include<vector>
    #include<list>
    #include<bitset>
    #include<set>
    #include<map>
    #include<time.h>
    using namespace std;
    #define LL long long
    #define bug(x)  cout<<"bug"<<x<<endl;
    const int N=1e2+10,M=2e6+10,inf=1e9+10;
    const LL INF=1e18+10,mod=998244353,MOD=998244353;
    const double eps=1e-8,pi=(4*atan(1.0));
    
    int Change(int year,int month,int day)
    {
        if(month==1||month==2)
        {
            month+=12;
            year--;
        }
        int c=year/100;
        int y=year%100;
        int m=month;
        int d=day;
        int W=c/4-2*c+y+y/4+26*(m+1)/10+d-1;
        if(W<0)
            return (W+(-W/7+1)*7)%7;
        return W%7;
    }
    int main()
    {
        int T,cas=1;
        scanf("%d",&T);
        while(T--)
        {
            int y,m,d,h,mi,s;
            scanf("%d-%d-%d %d:%d:%d",&y,&m,&d,&h,&mi,&s);
            printf("Case #%d: ",cas++);
            int flag=0,ans1=-1,ans2=-1;
            for(int i=1;;i++)
            {
                if(Change(y,m,i)==0)
                {
                    flag++;
                    if(flag==1)ans1=i;
                    else ans2=i;
                    if(flag==2)break;
                }
            }
            if(m==3)
            {
                if(d<ans2)printf("PST
    ");
                else if(d>ans2)printf("PDT
    ");
                else
                {
                    if(h==2)printf("Neither
    ");
                    else if(h<2)printf("PST
    ");
                    else printf("PDT
    ");
                }
            }
            else if(m==11)
            {
                if(d<ans1)printf("PDT
    ");
                else if(d>ans1)printf("PST
    ");
                else
                {
                    if(h==1)printf("Both
    ");
                    else if(h>1)printf("PST
    ");
                    else printf("PDT
    ");
                }
            }
            else if(m>3&&m<11)printf("PDT
    ");
            else printf("PST
    ");
        }
        return 0;
    }

    Daylight Saving Time

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 279    Accepted Submission(s): 142


    Problem Description
    Last month, xiaodao together with her friend poteko took a flight from San Francisco to Shanghai.
    When they were driving to the airport, xiaodao suddenly realized that the clock time on potekos car is one hour faster than the clock time on her mobile phone. And both of them might be correct, but how can it be? Because that day was Nov 6th, the Daylight saving time switch day this year.
    Daylight saving time (DST) or summer time is the practice of advancing clocks during summer months by one hour so that evening daylight lasts an hour longer. It is arguable that using DST can reduce overall energy consumption. Not all of us are using DST now, and for those regions adopting DST, the practices are also different.
    In the case of California, effective in the U.S. in 2007 as a result of the Energy Policy Act of 2005, the local time changes from Pacific Standard Time (PST) to Pacific Daylight Time (PDT) at 02:00 to 03:00 on the second Sunday in March and the local time changes back from PDT to PST at 02:00 to 01:00 on the first Sunday in November.
    Because it is one hour longer on that day, so xiaodao and poteko didn’t miss the flights, but they found it still a little confusing. Interestingly, once xiaodao went back to Shanghai, she met a bug caused by exactly the same issue during the work. You might also be in trouble with DST some day, so here comes this problem and hope it will be helpful.
    The local time in California without specifying whether it is PST or PDT could be ambiguous in some cases (e.g. 2016-11-06 01:25:00). In this problem, you are given a local time in California.
    Check whether it is “PST”, “PDT”, “Both” or “Neither”.
     
    Input
    The first line of the input gives the number of test cases, T.
    T test cases follow. Each test case consists of one line, a date string written in the following format: YYYY-MM-DD HH:MM:SS.
     
    Output
    For each test case, first output one line containing “Case #x: ”, where x is the test case number (starting from 1), following a result string which in one of “PST”, “PDT”, “Both” or “Neither”.
     1 ≤ T ≤ 1000.
     date will be legal and between “2007-01-01 00:00:00” and “2100-12-31 23:59:59”.
     
    Sample Input
    4 2016-03-13 01:59:59 2016-03-13 02:00:00 2016-11-06 00:59:59 2016-11-06 01:00:00
     
    Sample Output
    Case #1: PST Case #2: Neither Case #3: PDT Case #4: Both
     
    Source
     
  • 相关阅读:
    雷文-武汉科技大学-软件工程-本科-20111020(2011年校园招聘找工作时的简历)
    雷文-武汉科技大学-软件工程-本科-20111020(2011年校园招聘找工作时的简历)
    大学生应当趁早谋划未来
    大学生应当趁早谋划未来
    提前了解客户背景很有必要
    提前了解客户背景很有必要
    雷文-武汉科技大学-软件工程-本科-20131118(我的最新简历)
    雷文-武汉科技大学-软件工程-本科-20131118(我的最新简历)
    《商君列传第八》–读书总结
    《商君列传第八》–读书总结
  • 原文地址:https://www.cnblogs.com/jhz033/p/7528210.html
Copyright © 2011-2022 走看看