当前位置: 代码迷 >> 综合 >> HDU 3969 Crazy Basketball Fan 模拟
  详细解决方案

HDU 3969 Crazy Basketball Fan 模拟

热度:83   发布时间:2024-01-13 18:20:40.0

再没有比这道题更纯的模拟了,只不过超长的描述和超多的细节,使得一般没人会在比赛中做这种题。太浪费时间了。 我是因为只会做这种题才去做这道题的,谁知道就这样调了一下午,在比赛结束前半分钟才A掉。从来没写过这么长的模拟。

这道题主要是就是细节的考虑,而且所有要注意的题目中都说了,没有阴人的地方, 所以题目中提到的一定要注意。

容易出错的地方:

1.比分板上的后三项,由于要求靠右对齐,所以用数字输出的话就比较麻烦,转化成字符串相对方便一点,不过要考虑到10次投篮以上的,还有可能100次以上,不过不知道数据中有没有这种变态数据,但是理论上是能达到这么多的。

2.投篮后被犯规,这一条题目上用很醒目的语句标注了,如果进了,就算一投一中,不进,不算尝试投篮。

3.助攻,我就是WA在这上面了,助攻是接到传球后立刻投篮得分才算助攻,中间如果穿插了其他的动作,比如暂停了,再回来就不算助攻了。

4.注意盖帽后,算被盖者尝试了一次投篮

5.抢断后和得到篮板后,注意持球队员要及时变为该队员,因为随后不会有某某球员 hold ball 语句出现。

6.我记得nba上过场的球员都是排在前面的,但这道题显然不是这样,是按名单输出的,上场了就输出数据,没上过直接输出DNP,注意前5名是肯定上过场得,中间换人时在标记一下。

总之,在做这道题的时候一定要理清思路,想明白所有情况再去敲,现场赛如果碰见这种大模拟,就放一放吧,除非想好了,而且代码功底很强,否则是不值得投资这种题的。

代码如下,写的十分乱,这也说明了当时思路的不清晰。




#include <iostream>
#include <map>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
using namespace std;
int main()
{int i, j, t, n, k;char team1[55], team2[55], tmp[122], tmp1[55][55], tmp2[55][55], fk[9];bool chuchang[3][13];int score[5], pts[5][55], off[5][55], def[5][55], reb[5][55], ast[5][55], pf[5][55], free[5][55][5], three[5][55][5], faqiu[55][55][5], stl[5][55], block[5][55];scanf("%d", &t);while(t--){memset(chuchang, 0, sizeof(chuchang));memset(score, 0, sizeof(score));memset(pts, 0, sizeof(pts));memset(off, 0, sizeof(off));memset(def, 0, sizeof(def));memset(reb, 0, sizeof(reb));memset(ast, 0, sizeof(ast));memset(pf, 0, sizeof(pf));memset(free, 0, sizeof(free));memset(three, 0, sizeof(three));memset(faqiu, 0, sizeof(faqiu));memset(stl, 0, sizeof(stl));memset(block, 0, sizeof(block));map<string, int>teamnum;map<string, int>num;scanf("%s %s %s", team1, tmp, team2);for(i = 1; i <= 12; i++){scanf("%s", tmp1[i]);string tmpname = tmp1[i];teamnum[tmpname] = 1;num[tmpname] = i;}for(i = 1; i <= 12; i++){scanf("%s", tmp2[i]);string tmpname = tmp2[i];teamnum[tmpname] = 2;num[tmpname] = i;}scanf("%d", &n);string pre = "", now = "";bool ispass = 0,  twoout = 0, threeout = 0, fa = 0, fangui = 0;getchar();for(k = 0; k < n; k++){gets(tmp);if(k == 0 || k == n - 1) continue;string str = tmp;if(str.find("Hold Ball") != -1){int len = str.length() - 10;string tt = str.substr(0, len);now = tt;fangui = false;}else if(str.find("Pass to") != -1){string tt = "";int len = str.length();for(i = 0; i < len; i++){if(str[i] == ' ') break;else tt += str[i];}pre = tt;ispass = true;now = str.substr(pre.length() + 9);}else if(str.find("Layup") != -1 || str.find("Slam Dunk") != -1 || str.find("Hook Shot") != -1  || str.find("Jump Shot") != -1 )twoout = true;else if(str.find("3pt Shot") != -1)threeout = true;else if(str.find("Missed") != -1){if(fa == true){faqiu[teamnum[now]][num[now]][2]++;fa = false;}else if(twoout == true){if(!fangui) free[teamnum[now]][num[now]][2]++;else fangui = false;twoout = false;}else if(threeout == true){if(!fangui){free[teamnum[now]][num[now]][2]++;three[teamnum[now]][num[now]][2]++;}else fangui = false;threeout = false;}ispass = false;}else if(str.find("Made") != -1){if(fa == true){pts[teamnum[now]][num[now]]++;score[teamnum[now]]++;faqiu[teamnum[now]][num[now]][2]++;faqiu[teamnum[now]][num[now]][1]++;fa = false;}else if(twoout){pts[teamnum[now]][num[now]] += 2;score[teamnum[now]] += 2;free[teamnum[now]][num[now]][1]++;free[teamnum[now]][num[now]][2]++;if(ispass){ast[teamnum[now]][num[pre]]++;ispass = false;}twoout = false;}else if(threeout){pts[teamnum[now]][num[now]] += 3;score[teamnum[now]] += 3;free[teamnum[now]][num[now]][1]++;free[teamnum[now]][num[now]][2]++;three[teamnum[now]][num[now]][2]++;three[teamnum[now]][num[now]][1]++;if(ispass){ast[teamnum[now]][num[pre]]++;ispass = false;}threeout = false;}ispass = false;}else if(str.find("Rebound") != -1){string tt = "";int len = str.length();for(i = 0; i < len; i++){if(str[i] == ' ') break;else tt += str[i];}if(teamnum[tt] != teamnum[now]){def[teamnum[tt]][num[tt]]++;reb[teamnum[tt]][num[tt]]++;}else if(teamnum[tt] == teamnum[now]){off[teamnum[tt]][num[tt]]++;reb[teamnum[tt]][num[tt]]++;}now = tt;ispass = false;twoout = false;threeout = false;}else if(str.find("Blocked") != -1){if(threeout){free[teamnum[now]][num[now]][2]++;three[teamnum[now]][num[now]][2]++;threeout = false;}else if(twoout){free[teamnum[now]][num[now]][2]++;twoout = false;}string tt = str.substr(11);block[teamnum[tt]][num[tt]]++;ispass = false;twoout = false;threeout = false;}else if(str.find("Foul") != -1){string tt = "";int len = str.length();for(i = 0; i < len; i++){if(str[i] == ' ') break;else tt += str[i];}pf[teamnum[tt]][num[tt]]++;if(twoout || threeout)fangui = true;}else if(str.find("Free Throw") != -1){fa = true;ispass = false;}else if(str.find("Substitution") != -1){int len = str.find("Substitution") + 25;string tt = str.substr(len);chuchang[teamnum[tt]][num[tt]] = 1;ispass = false;twoout = false;threeout = false;}else if(str.find("Timeout") != -1)ispass = false;else if(str.find("Jump Ball") != -1)ispass = false;else if(str.find("Steal") != -1){string tt = "";int len = str.length();for(i = 0; i < len; i++){if(str[i] == ' ') break;else tt += str[i];}stl[teamnum[tt]][num[tt]]++;now = tt;ispass = false;}}printf("%s %d-%d %s\n", team1, score[1], score[2], team2);printf("%s\n", team1);puts("              PLAYER PTS OFF DEF REB AST STL BLK PF FGM-A 3PM-A FTM-A");for(i = 1; i <= 12; i++){if(i <= 5 || chuchang[1][i] == 1){printf("%20s%4d%4d%4d%4d%4d%4d%4d%3d", tmp1[i], pts[1][i], off[1][i], def[1][i], reb[1][i], ast[1][i], stl[1][i], block[1][i], pf[1][i]);sprintf(fk, "%d-%d", free[1][i][1], free[1][i][2]);printf("%6s", fk);sprintf(fk, "%d-%d", three[1][i][1], three[1][i][2]);printf("%6s", fk);sprintf(fk, "%d-%d", faqiu[1][i][1], faqiu[1][i][2]);printf("%6s\n", fk);}else{printf("%20s", tmp1[i]);puts("          DNP - Coach's Decision");}}printf("%s\n", team2);puts("              PLAYER PTS OFF DEF REB AST STL BLK PF FGM-A 3PM-A FTM-A");for(i = 1; i <= 12; i++){if(i <= 5 || chuchang[2][i] == 1){printf("%20s%4d%4d%4d%4d%4d%4d%4d%3d", tmp2[i], pts[2][i], off[2][i], def[2][i], reb[2][i], ast[2][i], stl[2][i], block[2][i], pf[2][i]);sprintf(fk, "%d-%d", free[2][i][1], free[2][i][2]);printf("%6s", fk);sprintf(fk, "%d-%d", three[2][i][1], three[2][i][2]);printf("%6s", fk);sprintf(fk, "%d-%d", faqiu[2][i][1], faqiu[2][i][2]);printf("%6s\n", fk);}else{printf("%20s", tmp2[i]);puts("          DNP - Coach's Decision");}}puts("");}return 0;
}