hdu 4462 Scaring the Birds(STL)
来源:互联网 发布:mac桌面东西不见了 编辑:程序博客网 时间:2024/06/05 20:25
题目链接:hdu 4462 Scaring the Birds
题目大意:给定N,表示有一个N∗N的农田,现在有些位置的谷物已经被毁坏,农场主决定在这些位置中选择一些放
置稻草人,给定每个点放置稻草人可以覆盖的曼哈顿距离。求最少放多少个稻草人。
解题思路:题意需要注意,可以放稻草人的位置是没有谷物的。然后对于每个位置预处理出可以覆盖的位置,用bitset
优化即可。
#include <cstdio>#include <cstring>#include <cstdlib>#include <set>#include <bitset>#include <algorithm>using namespace std;const int maxn = 55;const int maxm = 15;const int inf = 0x3f3f3f3f;bitset<maxn * maxn> s, p[maxm];int N, K, R[maxm], C[maxm], D[maxm];int g[maxn][maxn];void init () { memset(g, 0, sizeof(g)); scanf("%d", &K); for (int i = 0; i < K; i++) { scanf("%d%d", &R[i], &C[i]); g[R[i]][C[i]] = 1; } for (int i = 0; i < K; i++) scanf("%d", &D[i]); for (int i = 0; i < K; i++) { p[i].reset(); for (int x = 1; x <= N; x++) { for (int y = 1; y <= N; y++) { if (g[x][y]) continue; if (abs(x - R[i]) + abs(y - C[i]) <= D[i]) p[i].set( (x-1) * N + y-1); } } }}int solve() { int ans = inf; for (int i = 0; i < (1<<K); i++) { int cnt = 0; s.reset(); for (int j = 0; j < K; j++) { if (i&(1<<j)) { cnt++; s |= p[j]; } } if (s.count() == N * N - K) ans = min(ans, cnt); } return ans == inf ? -1 : ans;}int main () { while (scanf("%d", &N) == 1 && N) { init(); printf("%d\n", solve()); } return 0;}
0 0
- hdu 4462 Scaring the Birds(STL)
- HDU 4462(Scaring the Birds)
- HDU 4462 Scaring the Birds
- HDU 4462 Scaring the Birds
- hdu 4462 Scaring the Birds
- HDU 4462 Scaring the Birds
- HDU 4462 Scaring the Birds
- HDU Scaring the Birds
- hdu 4462 Scaring the Birds 状态压缩
- [dfs+水] hdu 4462 Scaring the Birds
- hdu 4462 Scaring the Birds (暴力)
- hdu 4462 Scaring the Birds(暴力,细读)
- hdu 4462 Scaring the Birds 回溯法
- HDU 4462 Scaring the Birds(dfs)
- HDU 4462 Scaring the Birds (枚举+暴搜)
- HDU 4462 Scaring the Birds (状态压缩 暴搞)
- HDU 4462Scaring the Birds(枚举所有状态)
- HDU 4462 Scaring the Birds (暴力枚举DFS)
- Http访问网络之GET和POST
- yum install rz sz
- java打印对象和toString方法
- Linux常用命令大全
- jQuery验证控件jquery.validate.js使用说明+中文API
- hdu 4462 Scaring the Birds(STL)
- 如何在Eclipse中显示空格(space)和制表符(tab)
- MINA2.0原理
- poj 2429 GCD & LCM Inverse 【java】+【数学】
- 拓扑排序之关键路径
- Fedora18 与XP 相互telnet问题(xp无法telnet Fedora)
- Tmutarakan Exams 简单的容斥定理
- Java代码规范、格式化和checkstyle检查配置文档
- Linux 源码编译与程序运行期间静态库与动态库搜索路径