• (中等) 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
    ",maxn);
        }
        
        return 0;
    }
    View Code
  • 相关阅读:
    .net批量插入SqlServer数据库的方法:
    Google主页中国元宵节
    左岸读书你是想读书,还是想读完书?
    Google主页中国著名教育家和画家 丰子恺先生 诞辰114周年
    【转载】图的遍历
    Google主页爱尔兰作家 布拉姆斯托克诞辰165周年
    诺基亚黯然关闭其在欧洲的最后一个手机工厂的背后
    [POJ 1012] Joseph(约瑟夫)
    台湾南投3.27地震
    左岸读书语不惊人死不休(95)
  • 原文地址:https://www.cnblogs.com/whywhy/p/4663601.html
Copyright © 2020-2023  润新知