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 ...
随机推荐
- AppCan应用开发之插件实践篇-支付插件
电商O2O无疑是目前最受用户欢迎的APP类型,而在这类APP中必不可少的就是在线支付功能了.在AppCan平台开发这类应用时,官方封装了微信支付.支付宝.银联等多种支付SDK,更接入了多家聚合支付平台 ...
- html转义函数
public static String filter(String message) { if (message == null) return (null); char content[] = n ...
- 20145129 《Java程序设计》第1周学习总结
20145129 <Java程序设计>第1周学习总结 教材学习内容总结 在第一章学习后初步了解了Java历史及发展,以及JCP,JSR,JVM的相关知识了解.JCP是一个开放性国际组织,由 ...
- 软件工程课后作业——用JAVA编写的随机产生30道四则运算
package com.java.sizeyunsuan; public class lianxi { String f() { int i=(int)(Math.random()*10); int ...
- git简单入门
git简单入门 标签(空格分隔): git git是作为程序员必备的技能.在这里就不去介绍版本控制和git产生的历史了. 首先看看常用的git命令: git init git add git comm ...
- 【转载】openldap 备份与导入 及相关问题--扩展
http://www.cnblogs.com/ccdc/p/3356518.html 摘要: 对openldap进行备份时,直接使用slapcat命令进行备份,使用ldapadd还原出现问题及解决. ...
- Bootstrap入门四:代码
1.内联代码 code: 通过 <code> 标签包裹内联样式的代码片段.灰色背景.灰色边框和红色字体. For example, <code><section>& ...
- 如何用pdfbox-app-1.8.10.jar批处理将pdf文档转换成text文档
1.首先下载pdfbox-app-1.8.10.jar(下载地址:http://pdfbox.apache.org/download.html) 2.将pdfbox-app-1.8.10.jar加载到 ...
- 断点续传 (HTTP) 归纳
由于最近项目中要上传较大的文件,基于公司原有的底层框架的局限性,对于大文件的传输都束手无策,基于文件传输的安全性,考虑用断点续传(HTTP)以及FTP上传两种方式实现下面归纳下HTTP续传和FTP上传 ...
- Python 文件读和写