题目链接

题意 : 在一个二维直角坐标系中,有n×n个洞,每个洞的坐标为(x,y), 0 ≤ xy < n,给你一把锤子可以打到地鼠,最开始的时候,你可以把锤子放在任何地方,如果你上一秒在(x1,y1),那下一秒直线移动到的整数点(x2,y2)与这个点的距离小于等于d,并且当锤子移动(x2,y2)这个点时,所有在两点的直线上的整点数都可以打到。例如(0,0)移动到(0,3)。如果(0,1),(0,2)有老鼠出现就会被打到。求能够打的最多老鼠。

思路 : Dp[i][j][k]代表点(i,j)在第k秒最多可以得多少分。等于dp[x][y][k-1](点(x,y)为任意一个一秒内能到达(i,j)的点)+ 两点确定的直线上出现的地鼠数。求最大值。

 //
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm> using namespace std ; int mapp[][][] ;
int dp[][][];
int n , d,m ; int gcd(int a,int b)
{
return (a == ) ? b : gcd(b % a, a) ;
} int getsum(int sx,int sy,int ex,int ey,int t)
{
if(sx == ex && sy == ey) return mapp[sx][sy][t] ;//同一个点
int dx = ex-sx,dy = ey-sy ;
int sum = ;
if(dx == )//如果两个点在同一行
{
if(sy > ey) swap(sy,ey) ;
for(int i = sy ; i <= ey ; i++)
sum += mapp[sx][i][t] ;
return sum ;
}
else if(dy == )//同一列
{
if(sx > ex) swap(sx,ex) ;
for(int i = sx ; i <= ex ; i++)
sum += mapp[i][sy][t] ;
return sum ;
}
else
{
int g = gcd(abs(dx),abs(dy)) ;
dx /= g ;
dy /= g ;
for(int i = ; i <= g ; i++)//这条斜线上的所有整点
sum += mapp[dx * i + sx][dy * i + sy][t] ;
return sum ;
}
}
int main()
{
while(cin >> n >> d >> m)
{
if(n == && d == && m == ) break ;
int x,y,t,tt = ;
memset(dp,,sizeof(dp)) ;
memset(mapp,,sizeof(mapp)) ;
for(int i = ; i < m ; i++)
{
cin >> x >> y >>t ;
mapp[x + d][y + d][t] = ;
tt = max(tt,t) ;
}
n += * d ;//因为锤子可以在某时刻到达盘外边。
for(int t1 = ; t1 <= tt ; t1 ++)
for(int i = ; i < n ; i ++)
for(int j = ; j < n ; j++)
{
int sx = max(i - d,) ;
int sy = max(j - d,) ;
int ex = min(i + d,n - ) ;
int ey = min(n - ,j + d) ;
for(int x = sx ; x <= ex ; x++)
for(int y = sy ; y <= ey ; y++)
if(((x - i)*(x - i)+(y - j)*(y - j)) <= d * d)
dp[i][j][t1] = max(dp[x][y][t1-]+getsum(x,y,i,j,t1),dp[i][j][t1]) ;
}
int maxx = ;
for(int i = ; i < n ; i++)
for(int j = ; j < n ; j++)
maxx = max(dp[i][j][tt],maxx) ;
printf("%d\n",maxx) ;
}
return ;
}

POJ 3034 Whac-a-Mole(DP)的更多相关文章

  1. poj - 1953 - World Cup Noise(dp)

    题意:n位长的01序列(0 < n < 45),但不能出现连续的两个1,问序列有多少种. 题目链接:id=1953" target="_blank">h ...

  2. POJ 2168 Joke with Turtles(DP)

    Description There is a famous joke-riddle for children: Three turtles are crawling along a road. One ...

  3. POJ 1485:Fast Food(dp)&& 面试题

    题目链接 题意 给出 n 个餐厅,m 个停车场,现在要将 n 个餐厅中的 m 个变成停车场,使得每个餐厅到最近的停车场的距离之和最短,输出哪个餐厅变成停车场和它服务哪些餐厅,还有最短距离之和. 思路 ...

  4. poj - 1050 - To the Max(dp)

    题意:一个N * N的矩阵,求子矩阵的最大和(N <= 100, -127 <= 矩阵元素 <= 127). 题目链接:http://poj.org/problem?id=1050 ...

  5. POJ 2533——Longest Ordered Subsequence(DP)

    链接:http://poj.org/problem?id=2533 题解 #include<iostream> using namespace std; ]; //存放数列 ]; //b[ ...

  6. POJ 3666 Making the Grade (DP)

    题意:输入N, 然后输入N个数,求最小的改动这些数使之成非严格递增即可,要是非严格递减,反过来再求一下就可以了. 析:并不会做,知道是DP,但就是不会,菜....d[i][j]表示前 i 个数中,最大 ...

  7. poj 3267 The Cow Lexicon(dp)

    题目:http://poj.org/problem?id=3267 题意:给定一个字符串,又给n个单词,求最少删除字符串里几个字母,能匹配到n个单词里 #include <iostream> ...

  8. 【POJ 3176】Cow Bowling(DP)

    题 Description The cows don't use actual bowling balls when they go bowling. They each take a number ...

  9. 【POJ】3616 Milking Time(dp)

    Milking Time Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10898   Accepted: 4591 Des ...

  10. 【POJ】2385 Apple Catching(dp)

    Apple Catching Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13447   Accepted: 6549 D ...

随机推荐

  1. golang的++与--

    http://godoc.golangtc.com/doc/faq#inc_dec 简单地说, 在golang中++,--操作是语句而不是表达式. 所以a=b++, return x++之类绝对提示错 ...

  2. 一些Iphone sqlite 的包装类

    相信很多人用iphone的Sqlite不会直接用C的方法,要么自己包装一层Object c的访问方法,要么用CoreData,下面我整理些目前所了结的一些Sqlite 包装类.  1.CoreData ...

  3. 读取、添加、删除、修改配置文件 如(Web.config, App.config)

    private Configuration config; public OperateConfig() : this(HttpContext.Current.Request.ApplicationP ...

  4. [转]ubuntu错误解决E: Sub-process /usr/bin/dpkg returned an error code (1)

    [转]ubuntu错误解决E: Sub-process /usr/bin/dpkg returned an error code (1) http://yanue.net/post-123.html ...

  5. Windows Server 2003服务器.net4.0+IIS6.0的服务器,IE11浏览器访问的不兼容性

    工作中发生了一件诡异的事情: 程序在Win7+.NET4.0+IIS7.5的服务器部署,IE8和IE11请求时,响应的样式都正常. 但是在美的同事反映说,Windows Server 2003服务器. ...

  6. 如何向VS2010中插入ActiveX控件并且附带相应的类

    上两篇文章中我们已经讲述了ActiveX控件的一些相关知识,本文中,简单说明一下如何在我们自己的程序中使用ActiveX控件.(仍以我们上节课的例子为例) 我们打开VS2010编辑器,新建一个基于对话 ...

  7. github实践操作

    一.本地仓库的创建和提交 1.下载并安装Git http://msysgit.github.io/,安装完成后在本地电脑创建一个git仓库并初始化本地仓库 2.在git目录下创建一个Readme.tx ...

  8. public、protect、private在父类子类中使用

    先贴出一张,直观的.估计大家都见过的关于public.protect.private的范围图 作用域 当前类 同一package 子孙类 其他package public     T         ...

  9. JavaWeb实现文件上传下载功能实例解析

    转:http://www.cnblogs.com/xdp-gacl/p/4200090.html JavaWeb实现文件上传下载功能实例解析 在Web应用系统开发中,文件上传和下载功能是非常常用的功能 ...

  10. 1565: [NOI2009]植物大战僵尸 - BZOJ

    Description Input Output仅包含一个整数,表示可以获得的最大能源收入.注意,你也可以选择不进行任何攻击,这样能源收入为0.Sample Input3 210 020 0-10 0 ...