POJ 2501

 1 #include<iostream>
 2 #include<iomanip>
 3 #include<stdio.h>
 4 #include<string>
 5 #include<math.h>
 6 using namespace std;
 7
 8 int main()
 9 {
10     //freopen("acm.acm","r",stdin);
11     string s;
12     int i;
13     double speed = 0.0;
14     double road;
15     double time;
16     double time1;
17     double past;
18     time = 0;
19     past = 0;
20     road = 0;
21     getline(cin,s);
22     time = (double(s[0]-‘0‘)*10.0+double(s[1]-‘0‘))+(double(s[3]-‘0‘)*10.0+double(s[4]-‘0‘))/60.0+(double(s[6]-‘0‘)*10.0+double(s[7]-‘0‘))/3600.0;
23     if(s.length() > 8)
24     {
25         for(i =  9; i < s.length(); ++ i)
26         {
27             speed = speed*10.0 + double(s[i]-‘0‘);
28         }
29     }
30     else
31     {
32         cout<<s<<" "<<"0.00 km"<<endl;
33     }
34     time *= 60;
35     while(getline(cin,s))
36     {
37         if(s.length() > 8)
38         {
39             time1 = (double(s[0]-‘0‘)*10.0+double(s[1]-‘0‘))+(double(s[3]-‘0‘)*10.0+double(s[4]-‘0‘))/60.0+(double(s[6]-‘0‘)*10.0+double(s[7]-‘0‘))/3600.0;
40             time1 *= 60.0;
41             past += speed*(time1-time);
42             time = time1;
43             speed = 0;
44             for(i =  9; i < s.length(); ++ i)
45             {
46                 speed = speed*10.0 + double(s[i]-‘0‘);
47             }
48         }
49         if(s.length() == 8)
50         {
51             time1 = (double(s[0]-‘0‘)*10.0+double(s[1]-‘0‘))+(double(s[3]-‘0‘)*10.0+double(s[4]-‘0‘))/60.0+(double(s[6]-‘0‘)*10.0+double(s[7]-‘0‘))/3600.0;
52             time1 *= 60.0;
53             cout<<s<<‘ ‘;
54             cout<<setiosflags(ios::fixed)<<setprecision(2)<<(speed*(time1-time)+past)/60.0<<‘ ‘<<"km"<<endl;
55         }
56     }
57
58 }
时间: 2024-10-23 21:56:31

POJ 2501的相关文章

poj 2501 Average Speed

Average Speed Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4842   Accepted: 2168 Description You have bought a car in order to drive from Waterloo to a big city. The odometer on their car is broken, so you cannot measure distance. But

POJ 2501 Average Speed(不错的一道水题)

[题目简述]:给出我们时间和速度,让我们求出走了多远的距离 [分析]:这道题开始的时候没有太明白什么时候输出,后来看了别人的题解就明白了. 关于此题的几点总结: 1.时间的输入方法:scanf("%d:%d:%d",&h,&m,&s),注意积累! 2.关于空格的的输入控制使用char ch = getchar(),同时它还作为了本题的一个是否输出的标识控制的条件. 3.多积累类似题目的方法. 代码参考http://blog.csdn.net/yujuan_mao

POJ 3259 Wormholes SPFA算法题解

本题其实也可以使用SPFA算法来求解的,不过就一个关键点,就是当某个顶点入列的次数超过所有顶点的总数的时候,就可以判断是有负环出现了. SPFA原来也是可以处理负环的. 不过SPFA这种处理负环的方法自然比一般的Bellman Ford算法要慢点了. #include <stdio.h> #include <string.h> #include <limits.h> const int MAX_N = 501; const int MAX_M = 2501; const

POJ 3259 Wormholes Bellman题解

本题就是需要检查有没有负环存在于路径中,使用Bellman Ford算法可以检查是否有负环存在. 算法很简单,就是在Bellman Ford后面增加一个循环判断就可以了. 题目故事很奇怪,小心读题. #include <stdio.h> #include <string.h> #include <limits.h> const int MAX_N = 501; const int MAX_M = 2501; const int MAX_W = 201; struct E

POJ - 3186 Treats for the Cows (区间DP)

题目链接:http://poj.org/problem?id=3186 题意:给定一组序列,取n次,每次可以取序列最前面的数或最后面的数,第n次出来就乘n,然后求和的最大值. 题解:用dp[i][j]表示i~j区间和的最大值,然后根据这个状态可以从删前和删后转移过来,推出状态转移方程: dp[i][j]=max(dp[i+1][j]+value[i]*k,dp[i][j-1]+value[j]*k) 1 #include <iostream> 2 #include <algorithm&

POJ 2533 - Longest Ordered Subsequence(最长上升子序列) 题解

此文为博主原创题解,转载时请通知博主,并把原文链接放在正文醒目位置. 题目链接:http://poj.org/problem?id=2533 Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence of the given numeric sequence (a1, a2, ..., aN) be any sequence (ai1, ai2, ..., aiK)

POJ——T2271 Guardian of Decency

http://poj.org/problem?id=2771 Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 5932   Accepted: 2463 Description Frank N. Stein is a very conservative high-school teacher. He wants to take some of his students on an excursion, but he is

POJ——T2446 Chessboard

http://poj.org/problem?id=2446 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 18560   Accepted: 5857 Description Alice and Bob often play games on chessboard. One day, Alice draws a board with size M * N. She wants Bob to use a lot of c

poj 1088 滑雪 DP(dfs的记忆化搜索)

题目地址:http://poj.org/problem?id=1088 题目大意:给你一个m*n的矩阵 如果其中一个点高于另一个点 那么就可以从高点向下滑 直到没有可以下滑的时候 就得到一条下滑路径 求最大的下滑路径 分析:因为只能从高峰滑到低峰,无后效性,所以每个点都可以找到自己的最长下滑距离(只与自己高度有关).记忆每个点的最长下滑距离,当有另一个点的下滑路径遇到这个点的时候,直接加上这个点的最长下滑距离. dp递推式是,dp[x][y] = max(dp[x][y],dp[x+1][y]+