POJ 3034 Whac-a-Mole(DP)
题意 : 在一个二维直角坐标系中,有n×n个洞,每个洞的坐标为(x,y), 0 ≤ x, y < 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)的更多相关文章
- poj - 1953 - World Cup Noise(dp)
题意:n位长的01序列(0 < n < 45),但不能出现连续的两个1,问序列有多少种. 题目链接:id=1953" target="_blank">h ...
- POJ 2168 Joke with Turtles(DP)
Description There is a famous joke-riddle for children: Three turtles are crawling along a road. One ...
- POJ 1485:Fast Food(dp)&& 面试题
题目链接 题意 给出 n 个餐厅,m 个停车场,现在要将 n 个餐厅中的 m 个变成停车场,使得每个餐厅到最近的停车场的距离之和最短,输出哪个餐厅变成停车场和它服务哪些餐厅,还有最短距离之和. 思路 ...
- poj - 1050 - To the Max(dp)
题意:一个N * N的矩阵,求子矩阵的最大和(N <= 100, -127 <= 矩阵元素 <= 127). 题目链接:http://poj.org/problem?id=1050 ...
- POJ 2533——Longest Ordered Subsequence(DP)
链接:http://poj.org/problem?id=2533 题解 #include<iostream> using namespace std; ]; //存放数列 ]; //b[ ...
- POJ 3666 Making the Grade (DP)
题意:输入N, 然后输入N个数,求最小的改动这些数使之成非严格递增即可,要是非严格递减,反过来再求一下就可以了. 析:并不会做,知道是DP,但就是不会,菜....d[i][j]表示前 i 个数中,最大 ...
- poj 3267 The Cow Lexicon(dp)
题目:http://poj.org/problem?id=3267 题意:给定一个字符串,又给n个单词,求最少删除字符串里几个字母,能匹配到n个单词里 #include <iostream> ...
- 【POJ 3176】Cow Bowling(DP)
题 Description The cows don't use actual bowling balls when they go bowling. They each take a number ...
- 【POJ】3616 Milking Time(dp)
Milking Time Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10898 Accepted: 4591 Des ...
- 【POJ】2385 Apple Catching(dp)
Apple Catching Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13447 Accepted: 6549 D ...
随机推荐
- Drawable
今天简单的介绍一下有关以下5中的应用: Statelistdrawable Layerdrawable Shapeddrawable Clipdrawable Animationdrawable 1. ...
- 九度oj 1530 最长不重复子串
原题链接:http://ac.jobdu.com/problem.php?pid=1530 字符串简单题,看似O(n^2)的复杂度10000的数据量会tle,其实最长不重复子串不超过26个嘛... 如 ...
- Run ionic web app in nodejs
首先需要express插件:sudo npm install express 将ionic project的www拷贝至wwwroot,新建server.js: var express = requi ...
- Block 块
代码块本质上是和其他变量类似.不同的是,代码块存储的数据是一个函数体.使用代码块是,你可以像调用其他标准函数一样,传入参数数,并得到返回值. 脱字符(^)是块的语法标记.按照我们熟悉的参数语法规约所定 ...
- (转)eclipse安装ADT插件重启后不显示Android SDK Manager和Android Virtual Device Manager图标的一种解决办法
文章来源:http://blog.csdn.net/zcyhappy1314/article/details/8307534 下面说的这种情况是在正确安装ADT插件的前提下,重启eclipse后,工具 ...
- [转]What’s Behind Ericsson’s OpenWebRTC Project?
[转]What’s Behind Ericsson’s OpenWebRTC Project? http://www.tuicool.com/articles/z6rAVrJ Ericsson’s O ...
- python 通过urllib模块在svn中下载文件
#_*_coding:utf-8_*_ import urllib def Schedule(a,b,c): ''' a:已经下载的数据块 b:数据块的大小 c:远程文件的大小 ''' per = 1 ...
- cnblogs用户体验
在使用博客园的这段时间内,我们感觉有优点也有缺点,下面谈谈我们的看法: 1.是什么样的用户?有什么样的心理?对cnblogs的期望值是什么? 我们是学生用户,使用cnblogs主要是提交作业记录自己的 ...
- 刷机总结(阿里云os-->android4.2.2)注明:本文不是教程
注明:本文不是教程 写这篇文章的目的:让准备刷机的人(无论你是小白还是老鸟,当然老鸟就不用看了)用最短的时间了解刷机过程 其实本来目的是准备将阿里云的2.3.7升级到3.0的,但是3.0没有针对基伍大 ...
- mysql的简单主从复制(ubuntu)
环境:两台ubuntu 12.04.5 虚拟机 mysql-server-5.5 master (192.168.240.130) slave (192.168.240.129) (1)查看二进 ...