Medium POJ 3034 WHAC-A-MOLE,DP.

Source: Internet
Author: User

Description

While visiting a traveling fun fair you suddenly has an urge to break the high score in the Whac-a-mole game. The goal of the Whac-a-mole game is to ... whack moles. With a hammer. The job easier you has first consulted the fortune teller and now you know the exact appearance patterns of the M Oles.

The moles appear out of holes occupying theN2 integer points (x,y) Satisfying 0≤x,y<NIn a two-dimensional coordinate system. At each time step, some moles'll appear and then disappear again before the next time step. After the moles appear but before they disappear, you is able to move your hammer in a straight line to any position (x2,y2) That's at distance at the most d from your current position (x1,y1). For simplicity, we assume this can only move your hammer to a point have an integer coordinates. A Mole is whacked if the center of the hole it appears out of are located on the line between (x1,y1) and (x2,y2) (including the endpoints). Every mole whacked earns a point. When the game is starts, before the first time step, you is able to place your hammer anywhere you see fit.

The problem is to hit the hamster, each time the farthest can move the d distance straight line, and then the straight sweep of the hamster are killed.

The data range is small, DP is good, dp[i][j][t] represents the maximum value of the hammer at this position (I,J) at T-second.

The problem should be noticed that the hammer may be parked outside and drunk.

And then he was in a straight line there a few times.

The code is as follows:

//The ━━━━━━ of gods and Beasts ━━━━━━//┏┓┏┓//┏┛┻━━━━━━━┛┻┓//┃┃//┃━┃//████━████┃//┃┃//┃┻┃//┃┃//┗━┓┏━┛//┃┃//┃┃//┃┗━━━┓//┃┣┓//┃┏┛//┗┓┓┏━━━━━┳┓┏┛//┃┫┫┃┫┫//┗┻┛┗┻┛////━━━━━━ Feel the ━━━━━━ of Meng Meng//author:whywhy//Created time:2015 July 20 Monday 20:03 48 seconds//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 namespacestd;Const intmaxn= the;intdp[maxn][maxn][ the];intn,d,m;intmap1[maxn][maxn][ the];intgcdintAintb) {    if(!a)returnb; returnGCD (b%a,a);}intSumintX1,intY1,intX2,intY2,intt) {    intdx=x2-x1,dy=y2-Y1; inttemp=gcd (ABS (DX), ABS (DY)); intret=0; if(temp) {DX/=temp; Dy/=temp; }     for(intI=0; i<=temp;++i) RET+=map1[x1+i*dx+5][y1+i*dy+5][t]; returnret;}intMain () {//freopen ("In.txt", "R", stdin); //freopen ("OUT.txt", "w", stdout);    intx,y,t; intMAXN;  while(~SCANF (" %d%d%d", &n,&d,&m) && n+d+M) {memset (DP,0,sizeof(DP)); memset (MAP1,0,sizeof(MAP1));  for(intI=1; i<=m;++i) {scanf (" %d%d%d",&x,&y,&t); ++map1[x+5][y+5][t]; }         for(intI=1; i<=Ten;++i) for(x=-5; x<n+6;++x) for(y=-5; y<n+6;++y) {MAXN=0;  for(intx1=-5; x1<n+6;++x1) for(inty1=-5; y1<n+6;++y1)if(d*d>= (x-x1) * (x-x1) + (y-y1) * (yy1)) 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(inti=-5; i<n+6;++i) for(intj=-5; j<n+6;++j) Maxn=max (maxn,dp[i+5][j+5][Ten]); printf ("%d\n", MAXN); }        return 0;}
View Code

Medium POJ 3034 WHAC-A-MOLE,DP.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.