2013长沙网赛E题Travel by Bike

题目链接:http://acm.zju.edu.cn/changsha/showProblem.do?problemId=26

题意:一个人从一个地方到另一个地方,长度为L,每小时速度为speed,周一到周五每天最多走8个小时,周末最多走4个小时,给出这个人出发的时间,问周几到达。

分析:水题,但是有个地方要注意,刚好是周期的倍数的时候,应该是当前天的前一天。

AC代码:

 1 #include<stdio.h>
 2 #include<string.h>
 3 char s[10];
 4 char day[7][10]={"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
 5 int main()
 6 {
 7     int i,d;
 8     double speed,L;
 9     while(scanf("%s%lf%lf",s,&L,&speed)!=EOF)
10     {
11         for(i=0;i<7;i++)
12             if(strcmp(s,day[i])==0)
13                 d=i;
14         int a=L/speed;
15         if(L-a*speed>=10e-6)
16             a++;
17         int b=a%48;
18         if(b==0)
19             d=(d+6)%7;
20         else
21         {
22             while(b>0)
23             {
24                 if(d>=0&&d<=4)
25                     b-=8;
26                 else
27                     b-=4;
28                 if(b>0)
29                     d=(d+1)%7;
30             }
31         }
32         printf("%s
",day[d]);
33     }
34     return 0;
35 }
View Code
原文地址:https://www.cnblogs.com/frog112111/p/3334754.html