您的位置:首页 > 其它

2013 ACM/ICPC Asia Regional Changsha Online Travel by Bike (基础题)

2013-09-24 17:40 375 查看
Travel by Bike

Time Limit: 1 SecondMemory 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

题意:

Fancy要去旅行,给你的信息是星期几启程、路程和车速。

行驶的条件是周一至周五可行驶8小时,周六至周日可行驶4小时,问到达目的地是星期几?

思路:

对题意进行模拟即可。

注意:当正好行驶n个周期时,到达目的地的时间是出发时间的前一天。

/*************************************************************************
> File Name: E.cpp
> Author: BSlin
> Mail:
> Created Time: 2013年09月22日 星期日 17时54分17秒
************************************************************************/

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <iterator>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#define MP make_pair
#define INF (1<<30)
#define PI acos(-1.0)
#define esp 1e-8
const int dx[4]={0,0,0,0};
using namespace std;
#define read freopen("in.txt","r",stdin)
#define write freopen("out.txt","w",stdout)
#if defined (_WIN32) || defined (__WIN32) || defined (WIN32) || defined (__WIN32__)
#define LL __int64
#define LLS "%" "I" "6" "4" "d"
#else
#define LL long long
#define LLS "%" "l" "l" "d"
#endif

enum Day{
Monday = 1,
Tuesday = 2,
Wednesday = 3,
Thursday = 4,
Friday = 5,
Saturday = 6,
Sunday = 7,
}day;

int main(int argc, char** argv) {
//read;
char s[15];
double length,speed,time;
int num;

while(scanf("%s%lf%lf",s,&length,&speed) != EOF) {
if(s[0] == 'M') day = Monday;
else if(s[0] == 'T'&&s[1]=='u') day = Tuesday;
else if(s[0] == 'W') day = Wednesday;
else if(s[0] == 'T'&&s[1] == 'h') day = Thursday;
else if(s[0] == 'F') day = Friday;
else if(s[0] == 'S'&&s[1] == 'a') day = Saturday;
else if(s[0] == 'S'&&s[1] == 'u') day = Sunday;
time = length / speed;
num = (int)time / 48;
time = time - num * 48;
while(time - 48 >= esp) {
time -= 48;
}
while((day <= 5 && time - 8 >= esp) || (day > 5 && day <= 7 && time - 4 >= esp)) {
if(day == 1){
time -= 8;
day = Tuesday;
}
else if(day == 2) {
time -= 8;
day = Wednesday;
}
else if(day == 3) {
time -= 8;
day = Thursday;
}
else if(day == 4) {
time -= 8;
day = Friday;
}
else if(day == 5) {
time -= 8;
day = Saturday;
}
else if(day == 6) {
time -= 4;
day = Sunday;
}
else if(day == 7) {
time -= 4;
day = Monday;
}
}
if(day == 1){
if(time < esp) printf("Sunday\n");
else printf("Monday\n");
}
else if(day == 2) {
if(time < esp) printf("Monday\n");
else printf("Tuesday\n");
}
else if(day == 3) {
if(time < esp) printf("Tuesday\n");
else printf("Wednesday\n");
}
else if(day == 4) {
if(time < esp) printf("Wednesday\n");
else printf("Thursday\n");
}
else if(day == 5) {
if(time < esp) printf("Thursday\n");
else printf("Friday\n");
}
else if(day == 6) {
if(time < esp) printf("Friday\n");
else printf("Saturday\n");
}
else if(day == 7) {
if(time < esp) printf("Saturday\n");
else printf("Sunday\n");
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: