(中等) 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 ...
随机推荐
- Lua 基础 -- 学习笔记
标签(空格分隔): Lua 1. Lua可以一次性给多个变量赋值 变量比赋值多,多的变量就赋值nil 变量比赋值少,多的赋值舍弃 local a, b, c = 1, 2, 3 print( a, b ...
- Checking the Calendar
Checking the Calendar time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Android OpenGL ES(一)OpenGL ES介绍
在学习Android OpenGL ES开发之前,你必须具备Java 语言开发经验和一些Android开发的基本知识,但并不需要有图形开发的经验,本教程也会涉及到一些基本的线性几何知识,如矢量,矩阵运 ...
- excel表转换成txt导入
insert into t_user(userid,username,usercard,corpid,roleid,phone,useradd,userpost,usermail,userpasswd ...
- m,mm,mmm的用法
通过查看android源码目录下的build/envsetup.sh文件,可知: - m: Makes from the top of the tree. - mm: Build ...
- Lightoj 1004 - Monkey Banana Problem
题目链接:http://acm.hust.edu.cn/vjudge/contest/121396#problem/F http://lightoj.com/volume_showproblem.ph ...
- Spring注解基本解读
在一个类中使用Spring对象,办法如下: 使用注解的形式注入 从ApplicationContext中获取. T t = new ApplicationContext.getBean("x ...
- ref和out,以及一般方法的引用参数和值参数寻解
对与ref和out的区别,我相信很多人都知道,这里我简单罗列下: 1.首先ref和out两种类型的参数都是可以将方法内对参数的修改传递到方法外面 2.ref参数需要在传递之前初始化,out不需要,ou ...
- 网络层 IP 协议首部格式与其配套使用的四个协议(ARP,RARP,ICMP,IGMP)
目录 IP协议首部格式地址解析协议 ARP逆向地址解析协议 RARP网际控制报文协议 ICMP网际组管理协议IGMP IP 数据报首部 IP数据报首部格式: 最高位在左边,记为0 bit:最低位在右边 ...
- make[1]: *** [/workopenwrt/trunk/staging_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/stamp/.tools_install_nnnnn] Error 2 make[1]: Leaving directory `/work/openwrt/trunk' make: *** [world]
主要原因是编译时未连上网,编译时需要下载些插件,连接网后,重启下系统再编译下.