(中等) POJ 3034 Whac-a-Mole,DP。
Description
While visiting a traveling fun fair you suddenly have an urge to break the high score in the Whac-a-Mole game. The goal of the Whac-a-Mole game is to… well… whack moles. With a hammer. To make the job easier you have first consulted the fortune teller and now you know the exact appearance patterns of the moles.
The moles appear out of holes occupying the n2 integer points (x, y) satisfying 0 ≤ x, y < n in a two-dimensional coordinate system. At each time step, some moles will appear and then disappear again before the next time step. After the moles appear but before they disappear, you are able to move your hammer in a straight line to any position (x2, y2) that is at distance at most d from your current position (x1, y1). For simplicity, we assume that you can only move your hammer to a point having integer coordinates. A mole is whacked if the center of the hole it appears out of is located on the line between (x1, y1) and (x2, y2) (including the two endpoints). Every mole whacked earns you a point. When the game starts, before the first time step, you are able to place your hammer anywhere you see fit.
题目就是打地鼠,每次最远能移动d距离的直线,然后直线扫过的地鼠都被打死。
数据范围很小,DP就好,dp[i][j][t]表示在t秒时锤子在(i,j)这个位置上的最大值。
这个题要注意锤子可能停在外面,也是醉了。
然后还被直线那里坑了几次。
代码如下:
// ━━━━━━神兽出没━━━━━━
// ┏┓ ┏┓
// ┏┛┻━━━━━━━┛┻┓
// ┃ ┃
// ┃ ━ ┃
// ████━████ ┃
// ┃ ┃
// ┃ ┻ ┃
// ┃ ┃
// ┗━┓ ┏━┛
// ┃ ┃
// ┃ ┃
// ┃ ┗━━━┓
// ┃ ┣┓
// ┃ ┏┛
// ┗┓┓┏━━━━━┳┓┏┛
// ┃┫┫ ┃┫┫
// ┗┻┛ ┗┻┛
//
// ━━━━━━感觉萌萌哒━━━━━━ // Author : WhyWhy
// Created Time : 2015年07月20日 星期一 20时03分48秒
// File Name : 3034.cpp #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h> using namespace std; const int MaxN=; int dp[MaxN][MaxN][];
int N,D,M;
int map1[MaxN][MaxN][]; int gcd(int a,int b)
{
if(!a)
return b; return gcd(b%a,a);
} int sum(int x1,int y1,int x2,int y2,int t)
{
int dx=x2-x1,dy=y2-y1;
int temp=gcd(abs(dx),abs(dy));
int ret=; if(temp)
{
dx/=temp;
dy/=temp;
} for(int i=;i<=temp;++i)
ret+=map1[x1+i*dx+][y1+i*dy+][t]; return ret;
} int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout); int x,y,t;
int maxn; while(~scanf("%d %d %d",&N,&D,&M) && N+D+M)
{
memset(dp,,sizeof(dp));
memset(map1,,sizeof(map1)); for(int i=;i<=M;++i)
{
scanf("%d %d %d",&x,&y,&t);
++map1[x+][y+][t];
} for(int i=;i<=;++i)
for(x=-;x<N+;++x)
for(y=-;y<N+;++y)
{
maxn=; for(int x1=-;x1<N+;++x1)
for(int y1=-;y1<N+;++y1)
if(D*D>=(x-x1)*(x-x1)+(y-y1)*(y-y1))
maxn=max(maxn,dp[x1+][y1+][i-]+sum(x,y,x1,y1,i)); dp[x+][y+][i]=maxn;
} maxn=; for(int i=-;i<N+;++i)
for(int j=-;j<N+;++j)
maxn=max(maxn,dp[i+][j+][]); printf("%d\n",maxn);
} return ;
}
(中等) POJ 3034 Whac-a-Mole,DP。的更多相关文章
- (中等) POJ 2948 Martian Mining,DP。
Description The NASA Space Center, Houston, is less than 200 miles from San Antonio, Texas (the site ...
- (中等) POJ 3280 Cheapest Palindrome,DP。
Description Keeping track of all the cows can be a tricky task so Farmer John has installed a system ...
- (中等) POJ 1191 棋盘分割,DP。
Description 将一个8*8的棋盘进行如下分割:将原棋盘割下一块矩形棋盘并使剩下部分也是矩形,再将剩下的部分继续如此分割,这样割了(n-1)次后,连同最后剩下的矩形棋盘共有n块矩形棋盘.(每次 ...
- 【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)
题目链接 理解了题意之后,这个题感觉状态转移还是挺好想的,实现起来确实有点繁琐,代码能力还有待加强,经过很长时间才发现bug.注意坐标可能是负的. #include <cstdio> #i ...
随机推荐
- MyBatis SQL配置文件中使用#{}取值为null时却不报错的解决方案。
原因是因为#{kh_id} 这个参数名为小写,我之前写成了大写{#KH_ID}所以取不到值
- 转:SSH原理与运用(二):远程操作与端口转发
作者:阮一峰 (Image credit: Tony Narlock) 七.远程操作 SSH不仅可以用于远程主机登录,还可以直接在远程主机上执行操作. 上一节的操作,就是一个例子: $ ssh use ...
- HTML+CSS D08浮动
1. <html> <head> <title>div浮动</title> <style type="text/css"> ...
- WPF中静态引用资源与动态引用资源的区别
WPF中静态引用资源与动态引用资源的区别 WPF中引用资源分为静态引用与动态引用,两者的区别在哪里呢?我们通过一个小的例子来理解. 点击“Update”按钮,第2个按钮的文字会变成“更上一层楼”, ...
- 修改apache配置文件去除thinkphp url中的index.php
例如你的原路径是 http://localhost/test/index.php/index/add那么现在的地址是 http://localhost/test/index/add如何去掉index. ...
- Android 系统编译
最近研究了下Android 的编译系统,下面结合编译我们自己的产品 mobot 来对整个编译系统进行必要的介绍,方便大家今 后对默认编译的修改. 先列出几个觉得重要的Make 文件: build/bu ...
- ormlite 删除操作
ormlite删除操作 DeleteBuilder<TransferDetailDtl, Integer> deleteBuilder = mRawDao.deleteBuilder(); ...
- Windows恢复Grub引导,用grub安装ubuntu
http://www.linuxidc.com/wap.aspx?nid=18027&p=&cp=&cid=http://m.blog.chinaunix.net/uid-22 ...
- php 文件夹遍历俩种对比
configu.phpindex.php新建文件夹 D:\xampp\htdocs\1test\use\useversion/configu.phpD:\xampp\htdocs\1test\use\ ...
- Redis(1)在windows环境下的安装和测试
初次准备使用redis,一个著名的nosql缓存数据库. 这里是第一天,就简单写一下windows下的安装,遇到的一些问题,然后简单的使用和测试,之后会在代码中使用和测试. 之后还会在生产环境中进行测 ...