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 ...
随机推荐
- PHP表单验证
<!DOCTYPE html> <html> <head> <title>Test Code</title> </head> & ...
- 使用MegaCli和Smartctl获取普通磁盘
设备名称: [root@DB232 shell]# cat /proc/scsi/scsi Attached devices:Host: scsi0 Channel: 02 Id: 00 Lun: 0 ...
- 修改setup.py的源
方法一: 修改文件 ~/.pydistutils.cfg为: [easy_install] index_url = http://pypi.douban.com/simple 方法二: 直接在setu ...
- visual studio的项目属性表
最近发现一个有趣的东西:visual studio的项目属性表 我下载了cocos2d-x-3.0alpha1,然后发现HelloLua项目配置里没有配include搜索目录和依赖库以及一个Marco ...
- (转)SQL Server 的事务和锁(二)-Range S-S锁
在这篇随笔中,我们的主要关注点在 Key-Range Lock.Key-Range Lock有 S-S.S-U.I-N.X-X几种情况.我们一个一个来说,力求明白.遗憾的是,这里可能会比较冗长,那么死 ...
- Java for LeetCode 023 Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 解 ...
- Eclipse 代码格式化
http://blog.csdn.net/prstaxy/article/details/7839197 http://jingyan.baidu.com/article/9158e00044efb6 ...
- wifi开发总结
转自:http://blog.csdn.net/kakaxi1o1/article/details/35625019 Unable to open connection to supplicant o ...
- 好久没弄了,来个最简的centos下的Iptables文件存照吧。
有最基本的作用.. # Generated by iptables-save v1. :: *filter :INPUT ACCEPT [:] :FORWARD ACCEPT [:] :OUTPUT ...
- pl/sql developer 登陆提示ORA-12514(转)
pl/sql developer 登陆提示ORA-12514 说明监听服务已经起来了 备注:通过 lsnrctl 命令来启动/停止/查看/重载监听器/服务 lsnrctl start|stop|s ...