hdu 1181 变形课
2015-07-15 20:50
211 查看
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1181
建图,遍历。。
建图,遍历。。
#include<algorithm> #include<iostream> #include<cstdlib> #include<cstring> #include<cstdio> #include<vector> #include<queue> #include<map> using std::map; using std::cin; using std::cout; using std::endl; using std::find; using std::sort; using std::pair; using std::queue; using std::vector; using std::multimap; #define pb(e) push_back(e) #define sz(c) (int)(c).size() #define mp(a, b) make_pair(a, b) #define all(c) (c).begin(), (c).end() #define iter(c) decltype((c).begin()) #define cls(arr,val) memset(arr,val,sizeof(arr)) #define cpresent(c, e) (find(all(c), (e)) != (c).end()) #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i) const int N = 26; bool vis , G ; typedef unsigned long long ull; void bfs(int s) { cls(vis, false); queue<int> q; q.push(s); vis[s] = true; while (!q.empty()) { int v = q.front(); q.pop(); rep(i, N) { if (!G[v][i] || vis[i]) continue; q.push(i); vis[i] = true; } } puts(vis['m' - 'a'] ? "Yes." : "No."); } int main() { #ifdef LOCAL freopen("in.txt", "r", stdin); freopen("out.txt", "w+", stdout); #endif char buf[40]; while (~scanf("%s", buf)) { if (buf[0] != '0') { G[buf[0] - 'a'][buf[strlen(buf) - 1] - 'a'] = true; } else { bfs(1); cls(G, false); } } return 0; }
相关文章推荐
- 基于事件的隐式调用风格
- POJ 1258 Agri-Net //Prim算法
- 静态文件服务器(The static file servers)
- 使用Windows BitLocker进行安全磁盘加密
- uva 1366(dp)
- iOS中runtime运行机制解析
- ZOJ 2770 Burn the Linked Camp 差分约束
- Windows批处理:请求远程协助
- bzoj2154
- Eclipse常见操作
- Linux下的LVM管理
- Linux下的LVM管理
- Labview软件的特点
- MySQL主从复制(Master-Slave)
- Codeforces 558A Lala Land and Apple Trees(Sort快排)
- Python垃圾回收机制
- 调用返回风格(面向对象与主程序子程序)
- 【MySQL】(2)数据类型与操作数据表
- Codeforces Round #312 (Div. 2) ABC题解
- Python.Scrapy.14-scrapy-source-code-analysis-part-4