题目链接

理解了题意之后,这个题感觉状态转移还是挺好想的,实现起来确实有点繁琐,代码能力还有待加强,经过很长时间才发现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)的更多相关文章

  1. 【POJ 3071】 Football(DP)

    [POJ 3071] Football(DP) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4350   Accepted ...

  2. poj 3311(状态压缩DP)

    poj  3311(状态压缩DP) 题意:一个人送披萨从原点出发,每次不超过10个地方,每个地方可以重复走,给出这些地方之间的时间,求送完披萨回到原点的最小时间. 解析:类似TSP问题,但是每个点可以 ...

  3. poj 1185(状态压缩DP)

    poj  1185(状态压缩DP) 题意:在一个N*M的矩阵中,‘H'表示不能放大炮,’P'表示可以放大炮,大炮能攻击到沿横向左右各两格,沿纵向上下各两格,现在要放尽可能多的大炮使得,大炮之间不能相互 ...

  4. poj 3254(状态压缩DP)

    poj  3254(状态压缩DP) 题意:一个矩阵里有很多格子,每个格子有两种状态,可以放牧和不可以放牧,可以放牧用1表示,否则用0表示,在这块牧场放牛,要求两个相邻的方格不能同时放牛,即牛与牛不能相 ...

  5. poj 2324 Anniversary party(树形DP)

    /*poj 2324 Anniversary party(树形DP) ---用dp[i][1]表示以i为根的子树节点i要去的最大欢乐值,用dp[i][0]表示以i为根节点的子树i不去时的最大欢乐值, ...

  6. (中等) POJ 3034 Whac-a-Mole,DP。

    Description While visiting a traveling fun fair you suddenly have an urge to break the high score in ...

  7. POJ 3034 Whac-a-Mole(DP)

    题目链接 题意 : 在一个二维直角坐标系中,有n×n个洞,每个洞的坐标为(x,y), 0 ≤ x, y < n,给你一把锤子可以打到地鼠,最开始的时候,你可以把锤子放在任何地方,如果你上一秒在( ...

  8. poj 1141 Brackets Sequence (区间dp)

    题目链接:http://poj.org/problem?id=1141 题解:求已知子串最短的括号完备的全序列 代码: #include<iostream> #include<cst ...

  9. POJ 3034 Whac-a-Mole

    Whac-a-Mole Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 3070 Accepted: 922 Descriptio ...

随机推荐

  1. LInux 安全测试

    [CVE-2013-2094]Linux PREF_EVENTS Local Root 2.6.37-3.8.10 x86_64 踩(0)http://zone.wooyun.org/content/ ...

  2. jlink安装

    https://www.segger.com/jlink-software.html?step=1&file=JLink_510p

  3. div隐藏

    <div style="display:none">                 <textarea id="BodyBox2" runa ...

  4. codeforces A. The Wall 解题报告

    题目链接:http://codeforces.com/problemset/problem/340/A 这道题目理解不难,就是在[a, b]区间内,找出同时能够被x和y整除的个数.第一次想当然的开了两 ...

  5. 【python-mysql】在ubuntu下安装python-mysql环境

    1.先安装mysql sudo apt-get install mysql-server apt-get isntall mysql-client sudo apt-get install libmy ...

  6. CodeForces - 417A(思维题)

    Elimination Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit  ...

  7. SQLHelper、DBUtil终极封装

    DBUtil.java package org.guangsoft.util; import java.io.InputStream; import java.sql.Connection; impo ...

  8. weblogic 安装和部署项目(原创)

    1.下载weblogic(含破解文件,土豪请支持正版,谢谢!) 2.安装如下图: 3.新建domain 4.打开weblogic Console 5.开始部署项目 6.部署成功

  9. sysctl命令详解

    个人一般sysctl -p 或sysctl -a比较多使用 sysctl配置与显示在/proc/sys目录中的内核参数.可以用sysctl来设置或重新设置联网功能,如IP转发.IP碎片去除以及源路由检 ...

  10. 干货分享:IBM StorwizeV7000部署与运维

    http://storage.it168.com/a2014/1211/1689/000001689526_3.shtml