HDU 4462(暴力枚举)
因为题目当中的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(暴力枚举)的更多相关文章
- HDU 6351暴力枚举 6354计算几何
Beautiful Now Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)T ...
- hdu 4414 暴力枚举
#include <cstdio> #include <cstring> #include <iostream> #include <cmath> #i ...
- HDU:3368-Reversi(暴力枚举)
Reversi Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Su ...
- HDU 6638 - Snowy Smile 线段树区间合并+暴力枚举
HDU 6638 - Snowy Smile 题意 给你\(n\)个点的坐标\((x,\ y)\)和对应的权值\(w\),让你找到一个矩形,使这个矩阵里面点的权值总和最大. 思路 先离散化纵坐标\(y ...
- hdu 1172 猜数字(暴力枚举)
题目 这是一道可以暴力枚举的水题. //以下两个都可以ac,其实差不多一样,呵呵 //1: //4 wei shu #include<stdio.h> struct tt { ],b[], ...
- BestCoder Round #50 (div.1) 1002 Run (HDU OJ 5365) 暴力枚举+正多边形判定
题目:Click here 题意:给你n个点,有多少个正多边形(3,4,5,6). 分析:整点是不能构成正五边形和正三边形和正六边形的,所以只需暴力枚举四个点判断是否是正四边形即可. #include ...
- hdu 4445 Crazy Tank (暴力枚举)
Crazy Tank Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- HDU - 1248 寒冰王座 数学or暴力枚举
思路: 1.暴力枚举每种面值的张数,将可以花光的钱记录下来.每次判断n是否能够用光,能则输出0,不能则向更少金额寻找是否有能够花光的.时间复杂度O(n) 2.350 = 200 + 150,买350的 ...
- 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 ...
- HDU 4770 Lights Against Dudely 暴力枚举+dfs
又一发吐血ac,,,再次明白了用函数(代码重用)和思路清晰的重要性. 11779687 2014-10-02 20:57:53 Accepted 4770 0MS 496K 2976 B G++ cz ...
随机推荐
- strcpy实现
#include <iostream> using namespace std; char *strcpy(char *strDest, const char *strSrc) { if ...
- [ZHUAN]Flask学习记录之Flask-SQLAlchemy
From: http://www.cnblogs.com/agmcs/p/4445583.html 各种查询方式:http://www.360doc.com/content/12/0608/11/93 ...
- [r]Seven habits of effective text editing
Seven habits of effective text editing(via) Bram Moolenaar November 2000 If you spend a lot of time ...
- Cocos2d-x中Vector使用
1.创建Vector对象 Vector().默认的构造函数. Vector(ssize_t capacity).创建Vector对象,并设置容量. Vector(const Vector<T&g ...
- 修改app名字
一张图说明问题 如果没有成功clean一下,或者卸载掉原有的重新生成一下 如果要修改路径名和工程名有个复杂的方法 http://blog.sina.com.cn/s/blog_a42013280101 ...
- NSDate 总结日期操作
IOS Object-c NSDate总结日期操作 //NSDate //1, 创建NSDate对象 NSDate *nowDate = [NSDate date]; NSLog(@"%@& ...
- Xcode 5 解决 The operation couldn’t be completed. (NSURLErrorDomain error -1012.) 问题
使用Xcode6.1 SVN 出现问题 The operation couldn’t be completed. (NSURLErrorDomain error -1012.) 解决方法: 打开终端 ...
- Spring 配置自动扫描spring bean配置
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w ...
- [UOJ Round#4 A] [#51] 元旦三侠的游戏 【容斥 + 递推】
题目链接:UOJ - 51 据说这题与 CF 39E 类似. 题目分析 一看题目描述,啊,博弈论,不会!等待爆零吧... 这时,XCJ神犇拯救了我,他说,这题可以直接搜啊. 注意!是用记忆化搜索,状态 ...
- hdu 5150 Sit sit sit
http://acm.hdu.edu.cn/showproblem.php?pid=5151 直接判断是不是素数,然后再注意1就行. #include <cstdio> #include ...