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. 旋转图css3

    <!doctype html><html> <head>  <meta charset="UTF-8">  <title> ...

  2. Tab选项卡的原生写法

    关键点:建立点击事件和显示事件的连接,即点li 1让对应的div1出来,很容易想到遍历.索引 ;;} ul,li{list-style: none;} .tab{background: rgba(2, ...

  3. javaScript 新学习:Array.contains 函数

    Array.contains 函数 确定指定对象是否是 Array 对象中的元素. 此函数是静态的,可在不创建对象实例的情况下调用. var itemExists = Array.contains(a ...

  4. UIView的layoutSubviews,initWithFrame,initWithCoder方法

    ****************************layoutSubviews************************************ layoutSubviews是UIView ...

  5. THOUGHTS: programming in linux... with third_party open sources... methods

    Actually I do not have experiences in programming with open sources/third party libs.. in linux.. I ...

  6. Linux学习 -- 软件包管理

    1 软件包类型 源码包 脚本安装包  install.sh  不常用 二进制包(rpm包.系统默认包) RedHat -- rpm包 Debian,Ubuntu -- beb包 2 RPM包命令管理 ...

  7. U3D游戏开发基础

    向量: 1. 向量的长度,即向量的模.计算公式为向量各个分量的平方和,然后开平方. 在D3DX库中,方法为:FLOAT  D3DXVec3Length(CONST  D3DXVECTOR3 * pV) ...

  8. dfs+dp思想的结合------hdu1078

    首先是题目的意思: 从一个正方形的0,0点开始走,只能横着走,竖着走,最多走k步,下一个点的数一定要比当前这个点的值大,每走一步,就加上下一个点的数据,问数据最大能有多少. 首先遇到这种题目,走来走去 ...

  9. 分类算法-----KNN

    摘要: 所谓K最近邻,就是k个最近的邻居的意思,说的是每个样本都可以用她最接近的k个邻居来代表.kNN算法的核心思想是如果一个样本在特征空间中的k个最相似的样本中的大多数属于某一个类别,则该样本也属于 ...

  10. 第19章 网络通信----TCP程序设计基础

    TCP网络程序设计是指利用Socket类编写通信程序.利用TCP协议进行通信的两个应用程序是有主次之分的,一个称为服务器程序,另一个称为客户机程序,两者的功能和编写方法大不一样. 1.InetAddr ...