题意:接力赛,有
n
段,总路程d,求每个队伍的平均速度。
思路:模拟。
坑点:浮点数误差,所以处理时间的时候用整数,尽量避免浮点数。
http://acm.hdu.edu.cn/showproblem.php?pid=1036
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define rep(i,a,b) for(int i = a ; i <= b ; i ++)
#define rrep(i,a,b) for(int i = b ; i >= a ; i --)
#define repE(p,u) for(Edge * p = G[u].first ; p ; p = p -> next)
#define cls(a,x) memset(a,x,sizeof(a))
#define eps 1e-8
using namespace std;
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e5+5;
const int MAXE = 2e5+5;
typedef long long LL;
typedef unsigned long long ULL;
int T,n,m,k;
void input() {
double d;
int t,m,s,ok,num;
char s1[10];
int v;
int Int,Dot;
double dot;
int sec;
scanf("%d %lf",&n,&d);
d = d ;
while(~scanf("%d",&num)) {
ok = 0;
sec = 0;
rep(i,1,n) {
scanf("%s",s1);
if(strcmp(s1,"-:--:--") == 0) ok = 1;
else {
sscanf(s1,"%d:%d:%d",&t,&m,&s);
sec += t * 3600 + m * 60 + s;
}
}
if(ok) printf("%3d: -\n",num);
else {
v = floor(sec / d + 0.5);
Int = v / 60;
Dot = v % 60;
printf("%3d: %d:%02d min/km\n",num,Int,Dot);
}
}
}
void solve() {
}
int main(void) {
input();
solve();
return 0;
}