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 (xy) satisfying 0 ≤ xy < 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 (x2y2) that is at distance at most d from your current position (x1y1). 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 (x1y1) and (x2y2) (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。的更多相关文章

  1. (中等) POJ 2948 Martian Mining,DP。

    Description The NASA Space Center, Houston, is less than 200 miles from San Antonio, Texas (the site ...

  2. (中等) POJ 3280 Cheapest Palindrome,DP。

    Description Keeping track of all the cows can be a tricky task so Farmer John has installed a system ...

  3. (中等) POJ 1191 棋盘分割,DP。

    Description 将一个8*8的棋盘进行如下分割:将原棋盘割下一块矩形棋盘并使剩下部分也是矩形,再将剩下的部分继续如此分割,这样割了(n-1)次后,连同最后剩下的矩形棋盘共有n块矩形棋盘.(每次 ...

  4. 【POJ 3071】 Football(DP)

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

  5. poj 3311(状态压缩DP)

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

  6. poj 1185(状态压缩DP)

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

  7. poj 3254(状态压缩DP)

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

  8. poj 2324 Anniversary party(树形DP)

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

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

    题目链接 理解了题意之后,这个题感觉状态转移还是挺好想的,实现起来确实有点繁琐,代码能力还有待加强,经过很长时间才发现bug.注意坐标可能是负的. #include <cstdio> #i ...

随机推荐

  1. Jenkins email-ext邮件通知模板

    http://blog.csdn.net/houyefeng/article/details/51344337 示例 以html格式发送送如下内容:邮件内容为项目名称.构建次数.触发原因.构建日志前1 ...

  2. 学习笔记——装饰器模式Decorator

    装饰器模式,最典型的例子. 工厂新开了流水线,生产了手机外壳,蓝天白云花色.刚准备出厂,客户说还要印奶牛在上面,WTF…… 时间上来不及,成本也不允许销毁了重来,怎么办?弄来一机器A,专门在蓝天白云的 ...

  3. PAT (Advanced Level) 1110. Complete Binary Tree (25)

    判断一棵二叉树是否完全二叉树. #include<cstdio> #include<cstring> #include<cmath> #include<vec ...

  4. 优化之zencart第一时间修改原始内容

    Zen Cart 基本修改指南 Zen Cart,全球顶级B2C商城网站!要想自行搭建一个基本的Zen Cart的网站,这篇文章是绝对不能错过的.目前我已经做了两个B2C网站,但是还是离不开这篇文章的 ...

  5. ab测试 uwsgi遇到的问题

    1 请求并发数目较大时,接收到的数目小于发送的数目 1.1 描述:uwsgi正常返回302跳转 ab -n 5000 -c 250 -g test.log "192.168.50.20:90 ...

  6. 浅谈ajax的优点与缺点

    AJAX (Asynchronous Javascript and XML) 是一种交互式动态web应用开发技术,该技术能提供富用户体验. 完全的AJAX应用给人以桌面应用的感觉.正如其他任何技术,A ...

  7. 关于MySQL中时间格式和取零点的问题

    select * from order where create_time>'2016-05-21 00:00:00'; 不包含2016-05-21 00:00:00时的订单 select * ...

  8. 用telnet命令,SMTP发送邮件

    邮件的发送是基于smtp协议的.邮件客户端软件给smtp服务器传送邮件和smtp服务器之间传送邮件也都是基于smtp协议的.邮件客户端软件接受邮件是主要基于pop3协议的. 下面介绍利用windows ...

  9. STM8|STM32 看门狗使用

    源:STM8|STM32 看门狗使用 STM8和STM32都配备了独立看门狗,其作用之大不言而喻.以下为STM8及STM32的独立看门狗使用例: 对于STM32单片机: #define SYS_IWD ...

  10. 面向对象重写(override)与重载(overload)区别

    一.重写(override) override是重写(覆盖)了一个方法,以实现不同的功能.一般是用于子类在继承父类时,重写(重新实现)父类中的方法. 重写(覆盖)的规则: 1.重写方法的参数列表必须完 ...