本文主要是介绍Codeforces Beta Round #87 (Div. 2) / 116B Little Pigs and Wolves (简单匹配),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
http://codeforces.com/problemset/problem/116/B
开始还打算打匈牙利的。。结果看到了这句话:
“there will be at most one wolf adjacent to each little pig”
也就是说,对于每头狼,若它周围有猪,就++cnt
因为不会出现两头狼吃同一只猪的情况。
完整代码:
/*30ms,0KB*/#include <iostream>
using namespace std;int main()
{int ans = 0, n, m, dirx[4], diry[4];dirx[0] = dirx[1] = diry[3] = diry[2] = 0;diry[0] = dirx[2] = 1;diry[1] = dirx[3] = -1;char map[20][20];cin >> n >> m;for (int i = 0; i <= n + 1; ++i)for (int j = 0; j <= m + 1; ++j)if (i && i <= n && j && j <= m) cin >> map[i][j];else map[i][j] = '.';for (int i = 1; i <= n; ++i)for (int j = 1; j <= m; ++j)if (map[i][j] == 'W')for (int k = 0; k < 4; ++k)if (map[i + dirx[k]][j + diry[k]] == 'P'){++ans;break;}cout << ans << endl;return 0;
}
这篇关于Codeforces Beta Round #87 (Div. 2) / 116B Little Pigs and Wolves (简单匹配)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!