HDU ACM 1181 变形课 (广搜BFS + 动态数组vector)-------第一次使用动态数组vector
2012-08-30 10:52
375 查看
http://acm.hdu.edu.cn/showproblem.php?pid=1181
题意:给我若干个单词,若单词A的结尾与单词B的开头相同,则表示A能变成B,判断能不能从b开头变成m结尾.
如: big-got-them
第一次使用动态数组vector
View Code
题意:给我若干个单词,若单词A的结尾与单词B的开头相同,则表示A能变成B,判断能不能从b开头变成m结尾.
如: big-got-them
第一次使用动态数组vector
View Code
#include <iostream> #include <vector> #include <queue> using namespace std; const int MAX = 30; int main() { vector <int> map[MAX]; bool used[MAX] = {0}; char str[110]; while(cin>>str) { int mark = 0; if(str[0] == '0') { queue <int> q; q.push('b' - 'a'); used['b' - 'a'] = 1; while(!q.empty()) { int mid = q.front(); q.pop(); int i; for(i=0;i<map[mid].size();i++) { if(!used[map[mid][i]]) { q.push(map[mid][i]); used[map[mid][i]] = 1; if(map[mid][i] == 'm'-'a') { mark = 1; break; } } } if(mark) { break; } } if(mark) { cout<<"Yes."<<endl; } else { cout<<"No."<<endl; } memset(used,0,sizeof(used)); int i; for(i=0;i<MAX;i++) { map[i].clear(); } } else { map[str[0] - 'a'].push_back(str[strlen(str) - 1] - 'a'); } } }
相关文章推荐
- 使用::std::vector作为管理动态数组的优先选择
- 使用::std::vector作为管理动态数组的优先选择
- 使用::std::vector作为管理动态数组的优先选择 作者原文出处:http://www.cpphelp.net/issue/vector.html
- 使用vector创建二维动态数组,并使用sort对其进行排序
- 使用::std::vector<>作为管理动态数组的优先选择
- java中动态数组Vector的使用实例
- 使用::std::vector作为管理动态数组的优先选择(转载)
- 使用::std::vector作为管理动态数组的优先选择
- effective STL - 尽量使用vector和string来代替动态分配的数组(char *)
- 使用vector和string代替动态申请的数组
- 使用C++ vector类创建动态数组
- 转:使用::std::vector作为管理动态数组的优先选择
- 使用vector建立结构体变量的数组,动态进行增加删除和显示
- 使用::std::vector作为管理动态数组的优先选择
- Effective STL 13 尽量使用vector和string来代替动态分配的数组
- java中动态数组Vector的使用实例
- 使用C语言实现vector动态数组的实例分享
- Vector:动态数组的使用和说明
- 使用vector 来取代临时动态分配数组空间
- 习题4.5:列出使用数组而不是vector的缺点