Poj-3034 Whac-A-Mole

Source: Internet
Author: User

DP

Write one by yourself .. After n times of WA, it becomes TLE ~ ... I can't bear it .. Later I referred to the online code. Final ac ~

Post people's code first ~

[Switch]

Idea: DP. It takes one day to change. In the DP section, DP [T] [x] [Y] indicates the maximum number of hamsters that can be hit when the hammer is stopped on (x, y) at the t time. Then DP [T] [x] [Y]
= Max (DP [T-1] [XX] [YY]
+ (XX, YY) the distance between (XX, YY), (x, y), and (x, y) in a straight line <D. But the most important thing is the following two points:

1:The renewal point may be out of the region., The following data: // very important !!!

20 5 4
1 0 1
0 1 1
0 5 2
1 6 2
The answer should be 4 instead of 3, which requires that the area be expanded to N + 2d.

2:(XX, YY) method for finding the number of new hamster (x, y). This is a long struggle. If a point is online (XX, YY) (x, y), the hamster above will also be hit. Check the code ....

 

Source code: (464 K, 563 ms)

# Include <iostream>
# Include <cmath>
# Include <algorithm>
# Define max (A, B) (a)> (B )? (A) (B ))
Using namespace STD;

 

Struct data {
   Int dx, Dy,
DW;
} Ste [2, 100];
Int N, N, D, M, K;
Int DP [15] [50] [50];
Int map [15] [50] [50];

 

Bool CMP (Data A, data B ){
   Return A. dw
<B. dw;
}

 

Bool inmap (int x, int y ){
   If (x
> = 0 & X
<= N & Y
> = 0 & Y
<= N) return true;
   Return
False;
}

 

Int gcd (int A, int B) {// maximum public factor
   If (B =
0)Return;
   Return
Gcd (B, A % B );
}

 

Int getsum (int t, int X, int y, int XX, int YY, int dx, int
Dy ){
   Int sum =
0;
   Do {
       
X + = DX, Y + = Dy;
       
Sum + = map [T] [x] [Y];
   } While (! (X
= XX & Y = YY ));
   Return
SUM;
}

 

Int main (){
   Int T, I, T,
SUM;
   Int x, y,
XX, YY, dx, Dy;
   For (k = 0, x
=-5; x <= 5; x
++)  
//Process all possible steps in five steps first. (D <= 5)
       
For (y =-5; y <= 5; y ++)
           
If (x * x + y * Y <= 25 ){
               
Ste [K]. dx = X;
               
Ste [K]. DY = y;
               
Ste [k ++]. DW = Ceil (SQRT (0.0 + x * x + y * y ));
           
}
   Sort (STE,
Ste + k, CMP );
   
While (scanf ("% d", & N, & D,
& M) & N ){
       
Memset (DP, 0, sizeof (DP ));
       
Memset (MAP, 0, sizeof (MAP ));
       
T =-1;
       
While (M --){
           
Scanf ("% d", & X, & Y,
& T );
           
Map [T] [x + D] [Y + D] = 1;
           
T = max (t, t );
       
}
       
T ++, n = n + 2 * D; 
// Extended area.
       
For (t = 1; t <t; t ++)
           
For (x = 0; x <= N; X ++)
               
For (y = 0; y <= N; y ++)
                   
For (I = 0; ste [I]. dw <= d
& I <K; I
++ ){
                       
DX = ste [I]. dx;

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.