标记数组初始化错了一位,导致WA了2次(其实第一次WA更sb,竟然输出时忘了Case数目) 错误的: memset(marks, 0, iTotalCards); 正确的: memset(marks+1, 0, iTotalCards); 完整代码: //pku1323 Game Prediction #include <cstdio> #include <algorithm> #include <functional> using namespace std; #define MAX_PLAYERS 20 #define MAX_PERCARDS 50 long cards[MAX_PERCARDS]; char marks[MAX_PLAYERS*MAX_PERCARDS + 1]; int main() { long iPlayers, iPerCards, iTotalCards; long i, j; long iCase = 0; while (2 == scanf("%ld%ld", &iPlayers, &iPerCards)) { if (0==iPlayers || 0==iPerCards) break; iTotalCards = iPlayers * iPerCards; memset(marks+1, 0, iTotalCards); for (i=0; i<iPerCards; i++) { scanf("%ld", &cards[i]); marks[ cards[i] ] = 1; } sort(cards, cards+iPerCards, greater<long>()); long iWin = 0; j = iTotalCards; for (i=0; i<iPerCards; i++) { while (marks[j]) j--; if (j < cards[i]) iWin++; else j--; } printf("Case %ld: %ld/n", ++iCase, iWin); } return 0; } 今天发现又轮到ZOJ挂掉了