uva352 The Seasonal War-python
来源:互联网 发布:策略模式 java用户界面 编辑:程序博客网 时间:2024/06/15 20:23
计算连通块,dfs
MAXN = 26dirs = [[1, 0], [0, 1], [-1, 0], [0, -1], [1, 1], [1, -1], [-1, 1], [-1, -1]]cnt = 0def dfs(x, y, m, n): flag[x][y] = 1 for d in dirs: nx = x + d[0] ny = y + d[1] if 0 <= nx < m and 0 <= ny < n and pic[nx][ny] == '1' and flag[nx][ny] == 0: dfs(nx, ny, m, n)while True: nn = raw_input() if not nn.isdigit(): break n = int(nn) flag = [[0 for col in range(MAXN)] for row in range(MAXN)] pic = [] ans = 0 cnt += 1 for i in range(n): pic.append(raw_input()) for i in range(n): for j in range(n): if pic[i][j] == '1' and flag[i][j] == 0: dfs(i, j, n, n) ans += 1 print("Image number "+str(cnt)+" contains "+str(ans)+" war eagles.")
0 0
- uva352 The Seasonal War-python
- 352The Seasonal War
- UVa 352 - The Seasonal War
- UVa 352 The Seasonal War
- UVA 352 The Seasonal War
- [uva-352]The Seasonal War (dfs和bfs两种
- The War
- Pacifism and the War
- zoj 3508 the war
- ZOJ 3508 The War
- The War&&贪心算法
- zoj 3500 The War
- deploy the war project
- zoj3508 The War 贪心
- HDOJ 4005 The war
- HDU 4005 The war
- The War(Zoj 3508)
- ZOJ-3508-The War
- The method of type must override a superclass method 解决方式
- JavaWeb
- 欧拉通路332. Reconstruct Itinerary
- replace()第二个参数为function时的小研究
- Repeated column in mapping for entity:(should be mapped with insert="false" update="false")
- uva352 The Seasonal War-python
- Youki的C++命名规则
- Plist文件
- iOS开发之ReplayKit框架学习
- yuekao=bean1
- CentOS6系统启动流程
- spring事务管理
- Spring声明式事务(Annotation注解方式)
- java处理Excel相关笔记