2013長沙網路賽 E題(水題 有點小bug)

果7發表於2013-09-23
Travel by Bike

Time Limit: 1 Second      Memory Limit: 32768 KB

Recently, Fancy is invited by his best friend to make a trip to his new house. Fancy is really excited by the invitation, so he's going to start the trip as soon as possible. But there are several difficulties to overcome. First, his friend is living in Changsha and Fancy is living in Hangzhou, so the trip is really a long one. Second, Fancy has only a bike to make this trip. Third, Fancy is a strange guy who would never work for longer than 8 hours on weekdays, and he would never work for longer than 4 hours on the weekend.

During this trip, Fancy thinks that riding bike is his only work. So on days of Monday to Friday, he will ride his bike 8 hours at most, and on Saturday and Sunday, he will ride 4 hours at most. Obviously, he will finish the trip as early as possible.

Now Fancy is going to start the trip, with information of road length and his riding speed, he wants to know that what day is his arriving day.

Input

There'll be several test cases. For each test case, there will be a string startday (startday ∈ {'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'}), an integerL (100 ≤ L ≤ 1000000000) and a float number s (5 ≤ s ≤ 30, with at most 3 decimal points). Here startday is the day which Fancy start the trip, L is the total length of the trip (in kilometer) and s is Fancy's riding speed (kilometer per hour).

Output

For each test case, please print the earlist day called arriveday which Fancy will arrive at Changsha. Please note that your output should fulfill arriveday ∈ {'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'}.

Sample Input

Monday 800 25.0
Sunday 300 5.0

Sample Output

Thursday
Monday


          題目大意:很簡單的程式碼哈哈!!很簡單的水題,輸入當前星期幾,然後是總共走的路程,每小時的速度。週一到週五每天可以行8小時,週六週日每天可以行4小時。問你走完這些路會在星期幾?

     解題思路:開始直接減去整週的,距離能整除每週48小時的算剩下的餘數。然後判斷是週一到週五再看距離,如果小於等於8*v,就直接跳出,表示這一天可以走到,不是的話l-=8*v,繼續。判斷是週一到週五再看距離,如果小於等於8*v,就直接跳出,表示這一天可以走到,不是的話l-=8*v,繼續。不過需要注意的是,可能會出現整除的情況,就是剛好距離是48*v的整數唄,這時候是(sta-1)%7就可以到達,而不是sta。這點debug了好久。具體見程式碼。

         題目地址:Travel by Bike

AC程式碼:
#include<iostream>
#include<cstring>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;
double eps=0.0001;
char a[7][20]= {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};

int main()
{
    char s[20];
    double l,v;  //距離與一小時的速度
    double weekv,eiv,fouv;
    //一週的路程,八小時的路程,四小時的路程
    int i,sta;
    while(~scanf("%s%lf%lf",s,&l,&v))
    {
        for(i=0; i<7; i++)
            if(strcmp(a[i],s)==0)
            {
                sta=i;
                break;
            }

        weekv=48.0*v,eiv=8.0*v,fouv=4.0*v;
        int len=l/weekv;
        l-=len*weekv;
        if(l==0)
            sta=(sta-1+7)%7;   //說明一個回合過來了,好不容易找出來的bug
        else
        {
            while(l>=0)
            {
                if(sta>=0&&sta<=4)  //週一到週五可以走到
                {
                    if(l<=eiv)
                        break;
                    l-=eiv;   //週一到週五不能走到
                    sta=(sta+1)%7;
                }
                else
                {
                    if(l<=fouv)  //週六到週日可以走到
                        break;
                    l-=fouv;
                    sta=(sta+1)%7;  //週六到週日不能走到
                }
            }
        }
        cout<<a[sta]<<endl;
    }
    return 0;
}


相關文章