2013 ACM/ICPC Asia Regional Changsha Online - E Travel by Bike
Travel by BikeTime 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 integer L (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
要注意,刚好是周期的倍数的时候,应该是当前天的前一天,这里错了很多次!
#include <iostream> #include <string.h> #include <math.h> #include <algorithm> #include <math.h> #include <stdio.h> using namespace std; double t[]={8,8,8,8,8,4,4}; int changestr(char str[]){ if(str[0]=='M'&&str[1]=='o')return 0; if(str[0]=='T'&&str[1]=='u')return 1; if(str[0]=='W'&&str[1]=='e')return 2; if(str[0]=='T'&&str[1]=='h')return 3; if(str[0]=='F'&&str[1]=='r')return 4; if(str[0]=='S'&&str[1]=='a')return 5; if(str[0]=='S'&&str[1]=='u')return 6; } int main() { //printf("%.6f\n",100000000/5.923); //printf("%.6f\n",100000000-(int)(100000000/5.923)*5.923); double l,one,tt; double s; char str[100]; int no,k; while(scanf("%s",str)!=EOF){ scanf("%lf%lf",&l,&s); k=changestr(str); one=48*s; no=(int )(l/one); if((l/one)!=no) { tt=l-one*(double)no; while(tt>0){ tt-=t[k]*s; if(tt<=0)break; k++; if(k>=7) k-=7; } } else k--; if(k<0)k+=7; if(k>=7)k-=7; switch (k){ case 0:printf("Monday\n");break; case 1:printf("Tuesday\n");break; case 2:printf("Wednesday\n");break; case 3:printf("Thursday\n");break; case 4:printf("Friday\n");break; case 5:printf("Saturday\n");break; case 6:printf("Sunday\n");break; } } return 0; }
补充:软件开发 , C++ ,