1. 程式人生 > >poj 1300 歐拉圖

poj 1300 歐拉圖

href col 估計 esp getchar() 歐拉 max namespace targe

http://poj.org/problem?id=1300

要不是書上有翻譯我估計要卡死,,,首先這是一個連通圖,鬼知道是那句話表示出來的,終點必須是0,統計一下每個點的度數,如果是歐拉回路那麽起點必須是0,因為起點等於終點。

如果是歐拉通路的話,起點必須不是0而且0的度數必須是奇數不然不滿足歐拉圖的定義。 還有就是輸入很操蛋,用的stringstream。

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<vector>
 5 #include<sstream>
 6
#define maxn 1<<15 7 using namespace std; 8 int cnt[25]; 9 int main() 10 { 11 char s[1005]; 12 int M,N,i,j,k,x; 13 while(cin>>s){ 14 if(!strcmp(s,"ENDOFINPUT")) break; 15 cin>>M>>N; 16 int odd=0,doors=0; 17 memset(cnt,0,sizeof(cnt));
18 getchar(); 19 for(i=0;i<N;++i) 20 { 21 22 gets(s); 23 stringstream ss(s); 24 while(ss>>x){ 25 // cout<<"x="<<x<<endl; 26 doors++; 27 cnt[i]++; 28 cnt[x]++;
29 } 30 } 31 for(i=0;i<N;++i) 32 if(cnt[i]%2==1) odd++; 33 //cout<<odd<<endl; 34 if(odd==0&&M==0){cout<<"YES "<<doors<<endl;} 35 else if(odd==2&&cnt[M]%2==1&&M!=0){cout<<"YES "<<doors<<endl;} 36 else puts("NO"); 37 cin>>s; 38 //puts("endend"); 39 } 40 return 0; 41 }

poj 1300 歐拉圖