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\n");
            else if(d>ans2)printf("PDT\n");
            else
            {
                if(h==2)printf("Neither\n");
                else if(h<2)printf("PST\n");
                else printf("PDT\n");
            }
        }
        else if(m==11)
        {
            if(d<ans1)printf("PDT\n");
            else if(d>ans1)printf("PST\n");
            else
            {
                if(h==1)printf("Both\n");
                else if(h>1)printf("PST\n");
                else printf("PDT\n");
            }
        }
        else if(m>3&&m<11)printf("PDT\n");
        else printf("PST\n");
    }
    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
 

转载于:https://www.cnblogs.com/jhz033/p/7528210.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值