hdu 5538 House Building(水)
2015-11-02 10:45
429 查看
题目链接:hdu 5538 House Building
代码
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn = 55; const int dir[][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; int N, M, G[maxn][maxn]; int main () { int cas; scanf("%d", &cas); while (cas--) { memset(G, 0, sizeof(G)); scanf("%d%d", &N, &M); for (int i = 1; i <= N; i++) for (int j = 1; j <= M; j++) scanf("%d", &G[i][j]); int ans = 0; for (int i = 1; i <= N; i++) { for (int j = 1; j <= M; j++) { if (G[i][j]) ans++; for (int d = 0; d < 4; d++) { int x = i + dir[d][0]; int y = j + dir[d][1]; //if (x <= 0 || x > N || y <= 0 || y > M) continue; ans += max(G[i][j] - G[x][y], 0); } } } printf("%d\n", ans); } return 0; }
相关文章推荐
- UITableView UITableViewStylePlain UITableViewStyleGrouped
- iOS7上TableViewCell的button和UIImageView个别未显示的bug
- hdu 5531 Rebuild(三分)
- ADT版本查看,This Android SDK requires Andr...ate ADT to the latest问题
- [js]Easyui组件扩展--fieldset
- js实现marquee头尾无缝滚动
- 【MySQL】unique列插入重复值解决方案
- 使用UGUI做下拉列表的方案
- UITextView 的placeholder
- LeetCode63——Unique Paths II
- 调用其他服务器的api时,暂时处理跨域问题的方法——No 'Access-Control-Allow-Origin' header is present on the requested resour
- UITableView没数据时用户提示该怎么做?
- LeetCode Implement Queue using Stacks 栈&队列
- UIScrollView常用属性和代理方法
- Self Sizing Cells tableView 自适应高度
- UICollectionView二级树展开
- iOS设置UICollectionViewCell的间距
- "IValueConverter" does not support converting from a string.——C# WPF 提示错误
- UI控件方法、属性的总结
- 关于UIview UIlabel Unbutton 的一些常用的属性方法(用以优化界面)