(中等) 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 (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=42;

int dp[MaxN][MaxN][15];
int N,D,M;
int map1[MaxN][MaxN][15];

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=0;

    if(temp)
    {
        dx/=temp;
        dy/=temp;
    }

    for(int i=0;i<=temp;++i)
        ret+=map1[x1+i*dx+5][y1+i*dy+5][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,0,sizeof(dp));
        memset(map1,0,sizeof(map1));

        for(int i=1;i<=M;++i)
        {
            scanf("%d %d %d",&x,&y,&t);
            ++map1[x+5][y+5][t];
        }

        for(int i=1;i<=10;++i)
            for(x=-5;x<N+6;++x)
                for(y=-5;y<N+6;++y)
                {
                    maxn=0;

                    for(int x1=-5;x1<N+6;++x1)
                        for(int y1=-5;y1<N+6;++y1)
                            if(D*D>=(x-x1)*(x-x1)+(y-y1)*(y-y1))
                                maxn=max(maxn,dp[x1+5][y1+5][i-1]+sum(x,y,x1,y1,i));

                    dp[x+5][y+5][i]=maxn;
                }

        maxn=0;

        for(int i=-5;i<N+6;++i)
            for(int j=-5;j<N+6;++j)
                maxn=max(maxn,dp[i+5][j+5][10]);

        printf("%d\n",maxn);
    }

    return 0;
}

时间: 2024-10-15 16:41:34

(中等) POJ 3034 Whac-a-Mole,DP。的相关文章

【POJ 3034】 Whac-a-Mole(DP)

[POJ 3034] Whac-a-Mole(DP) Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 3621   Accepted: 1070 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 W

(中等) POJ 3280 Cheapest Palindrome,DP。

Description Keeping track of all the cows can be a tricky task so Farmer John has installed a system to automate it. He has installed on each cow an electronic ID tag that the system will read as the cows pass by a scanner. Each ID tag's contents are

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

Description 将一个8*8的棋盘进行如下分割:将原棋盘割下一块矩形棋盘并使剩下部分也是矩形,再将剩下的部分继续如此分割,这样割了(n-1)次后,连同最后剩下的矩形棋盘共有n块矩形棋盘.(每次切割都只能沿着棋盘格子的边进行) 原棋盘上每一格有一个分值,一块矩形棋盘的总分为其所含各格分值之和.现在需要把棋盘按上述规则分割成n块矩形棋盘,并使各矩形棋盘总分的均方差最小. 均方差,其中平均值,xi为第i块矩形棋盘的总分. 请编程对给出的棋盘及n,求出O'的最小值. 题目好像很经典,DP问题,直

(中等) POJ 2948 Martian Mining,DP。

Description The NASA Space Center, Houston, is less than 200 miles from San Antonio, Texas (the site of the ACM Finals this year). This is the place where the astronauts are trained for Mission Seven Dwarfs, the next giant leap in space exploration.

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)

POJ 3034 DP

打地鼠游戏中,你有一个锤子,每一秒钟你可以拿着锤子移动d个单位的距离,必须是直线,掠过的鼠洞中露出的地鼠都会被锤打至,而事先知道从开始时各时间段内出现在老鼠的数量和位置,问题是从游戏开始至结束时,你最多能打到多少只地鼠,开始时锤子可以在任何位置. 题目有个陷阱, 只是说Moles出现的坐标为正,但没说hammer移动的位置要为正,可以为"any position" 所以锤子可以移出矩阵,再从矩阵外一点移进来 例: 20 5 4 1 0 1 0 1 1 0 5 2 1 6 2 0 0 0

poj 3034 Whac-a-Mole

http://poj.org/problem?id=3034 题意:打地鼠游戏中,你有一个锤子,每一秒钟你可以拿着锤子移动d个单位的距离,掠过的鼠洞中露出的地鼠都会被锤打至,而事先知道从开始时各时间段内出现在老鼠的数量和位置,问题是从游戏开始至结束时,你最多能打到多少只地鼠,开始时锤子可以在任何位置. 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 using namespace std

POJ 1692 Crossed Matchings(DP)

Description There are two rows of positive integer numbers. We can draw one line segment between any two equal numbers, with values r, if one of them is located in the first row and the other one is located in the second row. We call this line segmen

POJ 3356 AGTC 最短编辑距离 DP

http://poj.org/problem?id=3356 题意: 给两个长度不大于1000的串,修改其中一个串使得两串相同,问最少修改次数.修改有三种,插入一个字符,删除一个字符,改变一个字符. 分析: 直接给方程. dp[i][j]表示第一个串前i位和第二串前j位匹配的最小修改次数. dp[0][0] = 0, dp[length(x)][length(y)]为答案. dp[i][j] = min(dp[i-1][j-1] + x[i] != y[j], dp[i-1][j] + 1, d