标签:
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1507
输入包含不超过100组数据。每组数据第一行为"START hh:mm:ss",表示比赛开始时刻为hh:mm:ss。最后一行为"END hh:mm:ss",即比赛结束时刻。二者之间至少会有一个SCORE信息,格式为"SCORE hh:mm:ss team score",其中team要么是"home"(主场)要么是"guest"(客场), score表示得分,为1,2或者3。这些信息保证按照时间从早到晚的顺序排列,且任意两条SCORE信息的时刻均不相同。比赛开始时间不会早于9:00,结束时间不会晚于同一天的21:00。注意,如果比赛开始时间为09:00:00,结束时间为09:00:01,比赛长度为1秒钟,而不是2秒钟。
对于每组数据,输出测试点编号和总耗电量。
START 09:00:00
SCORE 09:01:05 home 2
SCORE 09:10:07 guest 3
END 09:15:00
START 09:00:00
SCORE 10:00:00 home 1
SCORE 11:00:00 home 1
SCORE 12:00:00 home 1
SCORE 13:00:00 home 1
SCORE 14:00:00 home 1
SCORE 15:00:00 home 1
SCORE 16:00:00 home 1
SCORE 17:00:00 home 1
SCORE 18:00:00 home 1
SCORE 19:00:00 home 1
SCORE 20:00:00 home 1
END 21:00:00
Case 1: 9672
Case 2: 478800
分析:
直接从开始时间模拟每一秒,只要是有队伍得分就增加耗电量,直到结束。
官方标程:
1 // Rujia Liu 2 #include<cstdio> 3 #include<iostream> 4 #include<string> 5 #include<cassert> 6 using namespace std; 7 8 int score1, score2, ans; 9 10 const int num[] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6}; 11 12 int s2t(const string& s) { 13 int hh, mm, ss; 14 sscanf(s.c_str(), "%d:%d:%d", &hh, &mm, &ss); 15 assert(hh>=9 && hh<=21 && mm>=0 && mm<=59 && ss>=0 && ss<=59); 16 int ans = hh * 3600 + mm * 60 + ss; 17 assert(ans>=9*3600 && ans<=21*3600); 18 return ans; 19 } 20 21 void accumulate(int score, int dt) { 22 char n[99]; 23 sprintf(n, "%d", score); 24 for(int i = 0; i < strlen(n); i++) 25 ans += dt * num[n[i] - ‘0‘]; 26 } 27 28 int main() { 29 int kase = 0, score; 30 string s, s2, team; 31 while(cin >> s >> s2) { 32 score1 = score2 = ans = 0; 33 assert(s == "START"); 34 int last_t = s2t(s2); 35 while(cin >> s >> s2) { 36 int t = s2t(s2); 37 assert(t > last_t); 38 accumulate(score1, t - last_t); 39 accumulate(score2, t - last_t); 40 last_t = t; 41 if(s == "END") break; 42 assert(s == "SCORE"); 43 44 cin >> team >> score; 45 assert(score>=1 && score<=3); 46 if(team == "home") score1 += score; 47 else if(team == "guest") score2 += score; 48 else assert(0); 49 } 50 cout << "Case " << ++kase << ": " << ans << "\n"; 51 } 52 return 0; 53 }
标签:
原文地址:http://www.cnblogs.com/jeff-wgc/p/4469986.html