POJ 3034 Whac-a-Mole(DP)
理解了题意之后,这个题感觉状态转移还是挺好想的,实现起来确实有点繁琐,代码能力还有待加强,经过很长时间才发现bug。注意坐标可能是负的。
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int dp[][][];
bool o[][][];
int n,ans,d;
int gcd(int a,int b)
{
return b == ?a:gcd(b,a%b);
}
int fun(int t,int x,int y,int tx,int ty,int ax,int ay)
{
int temp = ;
while(x != ax||y != ay)//开始这里写成&&
{
if(o[t+][x][y])
temp ++;
x += tx;
y += ty;
}
return temp+o[t+][x][y];
}
void judge(int t,int x,int y)
{
int i,j,g;
for(i = x-d;i <= x+d;i ++)
{
for(j = y-d;j <= y+d;j ++)
{
if((i-x)*(i-x)+(j-y)*(j-y) > d*d) continue;
if(i < ||j < ) continue;
if(i > n+||j > n+) continue;
g = gcd(abs(i-x),abs(j-y));
if(g == ) g = ;
int tx,ty;
tx = (i-x)/g;
ty = (j-y)/g;
dp[t+][i][j] = max(dp[t+][i][j],dp[t][x][y]+fun(t,x,y,tx,ty,i,j));
ans = max(dp[t+][i][j],ans);
}
}
}
int main()
{
int m,i,j,k,y,x,t;
while(scanf("%d%d%d",&n,&d,&m)!=EOF)
{
if(n == &&d == &&m == ) break;
memset(dp,,sizeof(dp));
memset(o,,sizeof(o));
for(i = ; i <= m; i ++)
{
scanf("%d%d%d",&x,&y,&t);
o[t][x+][y+] = ;
}
ans = ;
for(i = ; i <= ; i ++)
{
for(j = ; j < n+; j ++)
{
for(k = ; k < n+; k ++)
{
judge(i,j,k);
}
}
}
printf("%d\n",ans);
}
return ;
}
POJ 3034 Whac-a-Mole(DP)的更多相关文章
- 【POJ 3071】 Football(DP)
[POJ 3071] Football(DP) Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4350 Accepted ...
- poj 3311(状态压缩DP)
poj 3311(状态压缩DP) 题意:一个人送披萨从原点出发,每次不超过10个地方,每个地方可以重复走,给出这些地方之间的时间,求送完披萨回到原点的最小时间. 解析:类似TSP问题,但是每个点可以 ...
- poj 1185(状态压缩DP)
poj 1185(状态压缩DP) 题意:在一个N*M的矩阵中,‘H'表示不能放大炮,’P'表示可以放大炮,大炮能攻击到沿横向左右各两格,沿纵向上下各两格,现在要放尽可能多的大炮使得,大炮之间不能相互 ...
- poj 3254(状态压缩DP)
poj 3254(状态压缩DP) 题意:一个矩阵里有很多格子,每个格子有两种状态,可以放牧和不可以放牧,可以放牧用1表示,否则用0表示,在这块牧场放牛,要求两个相邻的方格不能同时放牛,即牛与牛不能相 ...
- poj 2324 Anniversary party(树形DP)
/*poj 2324 Anniversary party(树形DP) ---用dp[i][1]表示以i为根的子树节点i要去的最大欢乐值,用dp[i][0]表示以i为根节点的子树i不去时的最大欢乐值, ...
- (中等) POJ 3034 Whac-a-Mole,DP。
Description While visiting a traveling fun fair you suddenly have an urge to break the high score in ...
- POJ 3034 Whac-a-Mole(DP)
题目链接 题意 : 在一个二维直角坐标系中,有n×n个洞,每个洞的坐标为(x,y), 0 ≤ x, y < n,给你一把锤子可以打到地鼠,最开始的时候,你可以把锤子放在任何地方,如果你上一秒在( ...
- poj 1141 Brackets Sequence (区间dp)
题目链接:http://poj.org/problem?id=1141 题解:求已知子串最短的括号完备的全序列 代码: #include<iostream> #include<cst ...
- POJ 3034 Whac-a-Mole
Whac-a-Mole Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 3070 Accepted: 922 Descriptio ...
随机推荐
- 【转】Solr安全设置——对外禁用管理后台
本文转自:http://www.devnote.cn/article/94.html 测试于:Solr 4.5.1, Jdk 1.6.0_45, Tomcat 6.0.37 | CentOS 5.7 ...
- Linux下永久修改主机名
红帽系列的Linux发行版主机名存放位置是/etc/sysconfig/network,Ubuntu Linux主机名存放位置是/etc/hostname,所以只要修改主机名存放文件便可以永久的修改计 ...
- HDU4870 Rating(概率)
第一场多校,感觉自己都跳去看坑自己的题目里去了,很多自己可能会比较擅长一点的题目没看,然后写一下其中一道概率题的题解吧,感觉和自己前几天做的概率dp的思路是一样的.下面先来看题意:一个人有两个TC的账 ...
- JavaScript、Jquery选择题
尚学堂Java EE软件工程师认证考试 试题库-选择题 一. 选择题(包括单选和双选) 1.B 在JavaScript中,以下变量命名非法的是( )(选择一项) A. numb_1 ...
- Emblog 备忘
emblog换后台:(如admin-->xx) 1.xx目录下的globals.php打开找到替换admin(1) 2.www目录下的t\index.php 中找到替换admin(1) 3.ww ...
- MVC自带的校验
一.添加控制器Home和Model数据 public class UserInfo { public int Id { get; set; } [Display(Name="用户名" ...
- protostuff简单应用
protobuf是谷歌推出的与语言无关.平台无关的通信协议,一个对象经过protobuf序列化后将变成二进制格式的数据,所以他可读性差,但换来的是占用空间小,速度快.居网友测试,它的序列化效率是xml ...
- innobackupex err2
报错: [root@DB dbdata]# innobackupex --defaults-file=/etc/my.cnf --user=root --password=123 /data/dbda ...
- hdu 1240:Asteroids!(三维BFS搜索)
Asteroids! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- mysql封装类
<?php ; ; $cnt = mysql_num_rows($rsPtr); ; ) { $id = ...