1092 - cur = q.front(); q.pop();...

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

View Full Document Right Arrow Icon
#include<iostream> #include<map> #include<vector> #include<string> #include<queue> using namespace std; enum { Size = 32, }; int num; struct Node { int v; double rate; }; vector<Node> exchange[Size]; double value[Size]; void build_map(){ int i; string first,second; int a,b; map<string,int> table; for(i=0;i<num;i++){ cin>>first; table[first] = i; exchange[i].clear(); } Node n; cin>>i; while(i--){ cin>>first>>n.rate>>second; a = table[first]; b = table[second]; n.v = b; exchange[a].push_back(n); } } int calc(int root){ int cur; double val; vector<Node>::iterator pn; queue<int> q; q.push(root); while(!q.empty()){
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: cur = q.front(); q.pop(); for(pn=exchange[cur].begin();pn !=exchange[cur].end();pn++){ val = pn-&gt;rate * value[cur]; if(val &gt; value[pn-&gt;v]){ if(pn-&gt;v == root) return 1; value[pn-&gt;v] = val; q.push(pn-&gt;v); } } } return 0; } int fun(){ int i,j; for(i=0;i&lt;num;i++){ for(j=0;j&lt;num;j++) value[j] = 0; value[i] = 1.0; if( calc(i) ) return 1; } return 0; } int main(){ int tstcase = 1; cin&gt;&gt;num; while(num){ build_map(); cout&lt;&lt;&quot;Case &quot;&lt;&lt;tstcase++&lt;&lt;&quot;: &quot;; if(fun()){ cout&lt;&lt;&quot;Yes&quot;&lt;&lt;endl; } else { cout&lt;&lt;&quot;No&quot;&lt;&lt;endl; } cin&gt;&gt;num; } return 0; }...
View Full Document

This note was uploaded on 02/18/2010 for the course CS 100 taught by Professor Acm during the Spring '10 term at Zhejiang University.

Page1 / 2

1092 - cur = q.front(); q.pop();...

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