因为题目当中的k比较小k <= 10,所以可以直接枚举,题目里面由两个trick, 一个是如果每个点都可以放稻草人的话,那么答案是0, 另外一个就是如果可以放稻草人的点不用被照到。知道了这两个基本上暴力既可以ac了

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = ;
struct Point {
int x, y;
int r;
}p[maxn];
bool vis[maxn][maxn];
int cnt;
bool vis2[maxn][maxn];
bool judge(int n, int k, int num)
{
memset(vis, false, sizeof(vis));
cnt = ;
for (int i = ; i < k; i++)
if (( << i) & num)
cnt++;
for (int i = ; i <= n; i++)
{
for (int j = ; j <= n; j++)
{
if (vis2[i][j]) continue;
for (int q = ; q < k; q++)
{
if (( << q) & num)
{
if (abs(p[q + ].x - i) + abs(p[q + ].y - j) <= p[q + ].r)
{
vis[i][j] = true;
break;
}
}
}
if (!vis[i][j]) return false;
}
}
return true;
}
int main()
{
int n, k;
while (~scanf("%d", &n) && n)
{
memset(vis2, false, sizeof(vis2));
scanf("%d", &k);
for (int i = ; i <= k; i++)
scanf("%d %d", &p[i].x, &p[i].y);
for (int i = ; i <= k; i++)
scanf("%d", &p[i].r);
for (int i = ; i <= k; i++)
vis2[p[i].x][p[i].y] = true;
bool flag = true;
for (int i = ; i <= n; i++)
for (int j = ; j <= n; j++)
{
if (!vis2[i][j]) {
flag = false;
break;
} } if (flag)
{
printf("0\n");
continue;
}
int ans = ;
int maxx = ( << k);
for (int i = ; i < maxx; i++)
{
if (judge(n, k, i))
{
ans = min(ans, cnt);
}
}
if (ans > )
puts("-1");
else
printf("%d\n", ans);
}
return ;
}

HDU 4462(暴力枚举)的更多相关文章

  1. HDU 6351暴力枚举 6354计算几何

    Beautiful Now Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)T ...

  2. hdu 4414 暴力枚举

    #include <cstdio> #include <cstring> #include <iostream> #include <cmath> #i ...

  3. HDU:3368-Reversi(暴力枚举)

    Reversi Time Limit: 5000/2000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)Total Su ...

  4. HDU 6638 - Snowy Smile 线段树区间合并+暴力枚举

    HDU 6638 - Snowy Smile 题意 给你\(n\)个点的坐标\((x,\ y)\)和对应的权值\(w\),让你找到一个矩形,使这个矩阵里面点的权值总和最大. 思路 先离散化纵坐标\(y ...

  5. hdu 1172 猜数字(暴力枚举)

    题目 这是一道可以暴力枚举的水题. //以下两个都可以ac,其实差不多一样,呵呵 //1: //4 wei shu #include<stdio.h> struct tt { ],b[], ...

  6. BestCoder Round #50 (div.1) 1002 Run (HDU OJ 5365) 暴力枚举+正多边形判定

    题目:Click here 题意:给你n个点,有多少个正多边形(3,4,5,6). 分析:整点是不能构成正五边形和正三边形和正六边形的,所以只需暴力枚举四个点判断是否是正四边形即可. #include ...

  7. hdu 4445 Crazy Tank (暴力枚举)

    Crazy Tank Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  8. HDU - 1248 寒冰王座 数学or暴力枚举

    思路: 1.暴力枚举每种面值的张数,将可以花光的钱记录下来.每次判断n是否能够用光,能则输出0,不能则向更少金额寻找是否有能够花光的.时间复杂度O(n) 2.350 = 200 + 150,买350的 ...

  9. HDU 3699 A hard Aoshu Problem(暴力枚举)(2010 Asia Fuzhou Regional Contest)

    Description Math Olympiad is called “Aoshu” in China. Aoshu is very popular in elementary schools. N ...

  10. HDU 4770 Lights Against Dudely 暴力枚举+dfs

    又一发吐血ac,,,再次明白了用函数(代码重用)和思路清晰的重要性. 11779687 2014-10-02 20:57:53 Accepted 4770 0MS 496K 2976 B G++ cz ...

随机推荐

  1. SSH config

    add  a file named 'config' , place in folder .ssh then you can use  "ssh yourname "quickly ...

  2. Python Lib:pyzmq

    http://git.oschina.net/gitlab/StartWithCoding/tree/master/example/python/pyzmq

  3. Apache:To Config The Vhost of Django Project

    It is not a good idea to use dev server in Production Environment. Apache or Nginx are good choice.B ...

  4. Java中权限修饰符public、private、protected和default的区别

    1.public 可以修饰类.成员变量和成员函数,没有任何限制,同一个包中,或者不同包中的类都可以自由访问 2.private 可以修饰成员变量和成员函数,只能在本类中使用 3.default (不写 ...

  5. 转:aptitude 命令详解

    原文:http://www.isspy.com/aptitude-%E5%91%BD%E4%BB%A4%E8%AF%A6%E8%A7%A3/ aptitude aptitude 是 Debian GN ...

  6. BZOJ 1057 棋盘制作

    Description 国际象棋是世界上最古老的博弈游戏之一,和中国的围棋.象棋以及日本的将棋同享盛名.据说国际象棋起源于易经的思想,棋盘是一个8*8大小的黑白相间的方阵,对应八八六十四卦,黑白对应阴 ...

  7. google yeoman

    Yeoman是Google的团队和外部贡献者团队合作开发的,他的目标是通过Grunt(一个用于开发任务自动化的命令行工具)和Bower(一个HTML.CSS.Javascript和图片等前端资源的包管 ...

  8. Dungeon Master(poj 2251)

    Description You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is co ...

  9. html 商品展示框

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  10. JAVA循环结合标签使用,控制跳转

    public static void main(String[] args) { outer: for (int i = 0; true; i++) { inner: for (int j = 0; ...