[ACM ] 315 RE

看板C_and_CPP (C/C++)作者 (皇牌殺手)時間16年前 (2009/04/17 22:54), 編輯推噓3(302)
留言5則, 3人參與, 最新討論串1/1
這是我的code 跑測試沒問題 但是一上傳就吃RE 找了很久都找不出原因 囧 請問有強者可以幫我指點一下嗎 先謝了~ #include<iostream> #include<vector> #include<cstring> #include<string> #include<algorithm> #define MAX 101 using namespace std; int g[MAX][MAX]; void make_set(int *set, int n) { for(int i = 1; i <= n; i++) set[i] = i; } void union_set(int *set, int n, int x, int y) { int min = (x < y)? x: y; int max = (x > y)? x: y; for(int i = 1; i <= n; i++) if(set[i] == max) set[i] = min; } int cc(int n, int ex) { int set[n+1], i, j; vector<int> count; vector<int>::iterator it; make_set(set, n); for(i = 1; i <= n; i++) for(j = 1; j <= n; j++) if(i != ex && j != ex && g[i][j] == 1 && set[i] != set[j]) union_set(set, n, set[i], set[j]); for(i = 1; i <= n; i++) if(i != ex) count.push_back(set[i]); sort(count.begin(), count.end()); it = unique(count.begin(), count.end()); count.resize(it - count.begin()); return count.size(); } int main() { int n, i, head, orig, critical; string str; while(cin >> n && n != 0) { memset(g, 0, sizeof(g)); while(getline(cin, str)) { if(str == "0") break; head = str[0]-'0'; for(i = 2; i < str.length(); i+=2) { g[head][str[i]-'0'] = 1; g[str[i]-'0'][head] = 1; } } orig = cc(n, 0); critical = 0; for(i = 1; i <= n; i++) if(cc(n, i) > orig) critical++; cout << critical << endl; } return 0; } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.138.71.223

04/17 23:27, , 1F
int set[n+1] 動態宣告? 應該不行吧 改用動態配置試試看@@
04/17 23:27, 1F

04/18 00:48, , 2F
如果不行應該會是 CE 而非 RE
04/18 00:48, 2F

04/18 00:57, , 3F
問題在你預設每個編號都只有一位數
04/18 00:57, 3F

04/18 00:57, , 4F
n 最大是可能到 99 的
04/18 00:57, 4F

04/18 11:07, , 5F
感謝樓上 AC了
04/18 11:07, 5F
文章代碼(AID): #19w9WrL- (C_and_CPP)
文章代碼(AID): #19w9WrL- (C_and_CPP)