1011 - nodenum--; for(i=0;i<nodenum;i++){...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
#include<cstdio> #include<vector> #include<utility> # using namespace std; u int signum, validnum,transnum; int nodenum; int tree[4096]; i vector< pair<int,int> > matrix[16][12]; v int travel(int node, int signal){ int child; i vector< pair<int,int> > &vec = matrix[signal][tree[node]]; vector< pair<int,int> >::iterator iter; v child = node *2 + 1; if(child >= nodenum || tree[child] ==-1 ){ /* Leaf node */ for(iter = vec.begin(); iter!= vec.end(); iter++){ return 1; } return 0; } for(iter = vec.begin(); iter!= vec.end(); iter++){ return 1; } return 0; } void fun(){ int level; int i; char alpha; scanf("%d ", &level); while(level != -1){ nodenum = 1<<(level+1);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: nodenum--; for(i=0;i&lt;nodenum;i++){ scanf(&quot;%c &quot;, &amp;alpha); if(alpha == '*'){ tree[i] = -1; } else { tree[i] = alpha -'a'; } } if(travel(0,0)){ printf(&quot;Valid\n&quot;); } else { printf(&quot;Invalid\n&quot;); } } scanf(&quot;%d &quot;, &amp;level); } } int main(){ int i,j,a,b; char end; int tstcase = 0; scanf(&quot;%d %d %d &quot;, &amp;signum, &amp;validnum, &amp;transnum); while(signum ){ validnum = signum - validnum; for(i=0;i&lt;signum;i++){ for(j=0;j&lt;transnum;j++){ matrix[i][j].clear(); do { scanf(&quot;%d %d%c&quot;, &amp;a,&amp;b,&amp;end); matrix[i][j].push_back( make_pair(a,b) ); } while(end != '\n'); } } } if(tstcase ++){ printf(&quot;\n&quot;); } printf(&quot;NTA%d:\n&quot;, tstcase); p fun(); f scanf(&quot;%d %d %d &quot;, &amp;signum, &amp;validnum, &amp;transnum); } return 0; }...
View Full Document

Page1 / 2

1011 - nodenum--; for(i=0;i&amp;amp;lt;nodenum;i++){...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online