Problem 1001 看我这解法有啥问题

jijiqw | 2015-05-22 20:31:36Author
#include <iostream> #include <math.h> #include <iomanip> using namespace std; int x,y; double x1,x2, y2; int n,i,j,k,m; int t; int a[102]; int b[102][102]; void scan(int c); int main(int argc, char** argv) { t=1; //cin>> t; //while(t){ while(cin>>n>>m){ i=0;j=0; n++;k=0; for(i=0;i<n;i++) for(j=0;j<n;j++){ b[i][j]=0; } while(m-->0){//记录入数组 cin>>x>>y; if(x==y){ k=1; } b[x][y]=1; b[x][0]++; b[0][y]++; } if(k==1){ cout<<"NO"<<endl; continue; } for(i=1;i<n;i++){//扫描每一行,如果不存在该行的依赖 if(b[0][i]==0){ scan(i); } } k=0; for(i=1;i<n;i++){ if(b[0][i]!=0){ k=1; break; } } if(k==0){ cout<<"YES"<<endl; }else{ cout<<"NO"<<endl; } } //cin>>x; return 0; } void scan(int c){ if(b[c][0]<=0)return ; for(int d=1; d<n ; d++ ){ if(b[c][d]==1){ b[c][d]=0; b[0][d]--; if(b[0][d]==0){ scan(d); } } } }
jijiqw | 2015-05-22 20:33:45# 1
排版乱了 给跪
#include &lt;iostream&gt;<br /> #include &lt;math.h&gt;<br /> #include &lt;iomanip&gt;<br /> using &nbsp;namespace &nbsp;std;<br /> <br /> int &nbsp; &nbsp;x,y;<br /> double &nbsp; x1,x2, y2;<br /> int n,i,j,k,m;<br /> int &nbsp;t;<br /> int &nbsp;a[102];<br /> int b[102][102];<br /> <br /> void &nbsp;scan(int c);<br /> <br /> int main(int argc, char** argv) {<br /> &nbsp;&nbsp; &nbsp;t=1;&nbsp;<br /> &nbsp;&nbsp; &nbsp;//cin&gt;&gt; t;<br /> &nbsp;&nbsp; &nbsp;//while(t){<br /> &nbsp;&nbsp; &nbsp;while(cin&gt;&gt;n&gt;&gt;m){<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;i=0;j=0;&nbsp;<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;n++;k=0;&nbsp;<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;for(i=0;i&lt;n;i++)<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;for(j=0;j&lt;n;j++){<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;b[i][j]=0;<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br /> &nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;while(m--&gt;0){//记录入数组&nbsp;<br /> &nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;cin&gt;&gt;x&gt;&gt;y;<br /> &nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if(x==y){<br /> &nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;k=1;&nbsp;&nbsp; &nbsp;<br /> &nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br /> &nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;b[x][y]=1;<br /> &nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;b[x][0]++;<br /> &nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;b[0][y]++;<br /> &nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}&nbsp;<br /> &nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if(k==1){<br /> &nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;cout&lt;&lt;"NO"&lt;&lt;endl;<br /> &nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;continue;<br /> &nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br /> &nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;for(i=1;i&lt;n;i++){//扫描每一行,如果不存在该行的依赖&nbsp;<br /> &nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if(b[0][i]==0){<br /> &nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;scan(i);<br /> &nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br /> &nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br /> &nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;k=0; &nbsp;<br /> &nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;for(i=1;i&lt;n;i++){<br /> &nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if(b[0][i]!=0){<br /> &nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; k=1;<br /> &nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; break;<br /> &nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br /> &nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br /> &nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if(k==0){<br /> &nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;cout&lt;&lt;"YES"&lt;&lt;endl;<br /> &nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}else{<br /> &nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;cout&lt;&lt;"NO"&lt;&lt;endl;<br /> &nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br /> &nbsp;&nbsp; &nbsp;}<br /> &nbsp;&nbsp; &nbsp;&nbsp;<br /> &nbsp;&nbsp; &nbsp;//cin&gt;&gt;x;<br /> &nbsp;&nbsp; &nbsp;return 0;<br /> }<br /> <br /> void &nbsp;scan(int c){<br /> &nbsp;&nbsp; &nbsp;if(b[c][0]&lt;=0)return ;<br /> &nbsp;&nbsp; &nbsp;<br /> &nbsp;&nbsp; &nbsp;for(int &nbsp;d=1; d&lt;n ; d++ ){<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if(b[c][d]==1){<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;b[c][d]=0;<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;b[0][d]--;<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if(b[0][d]==0){<br /> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;scan(d);<br /> &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br /> &nbsp;&nbsp; &nbsp;}<br /> }
jijiqw | 2015-05-22 20:34:17# 2
排版乱了 给跪
#include <iostream> #include <math.h> #include <iomanip> using namespace std; int x,y; double x1,x2, y2; int n,i,j,k,m; int t; int a[102]; int b[102][102]; void scan(int c); int main(int argc, char** argv) { t=1; //cin>> t; //while(t){ while(cin>>n>>m){ i=0;j=0; n++;k=0; for(i=0;i<n;i++) for(j=0;j<n;j++){ b[i][j]=0; } while(m-->0){//记录入数组 cin>>x>>y; if(x==y){ k=1; } b[x][y]=1; b[x][0]++; b[0][y]++; } if(k==1){ cout<<"NO"<<endl; continue; } for(i=1;i<n;i++){//扫描每一行,如果不存在该行的依赖 if(b[0][i]==0){ scan(i); } } k=0; for(i=1;i<n;i++){ if(b[0][i]!=0){ k=1; break; } } if(k==0){ cout<<"YES"<<endl; }else{ cout<<"NO"<<endl; } } //cin>>x; return 0; } void scan(int c){ if(b[c][0]<=0)return ; for(int d=1; d<n ; d++ ){ if(b[c][d]==1){ b[c][d]=0; b[0][d]--; if(b[0][d]==0){ scan(d); } } } }
Herobs | 2015-05-22 23:49:43# 3
怎么全是贴代码的