UVA 10360 Rat Attack

Source: Internet
Author: User

Rat Attack

input: standard input

Output: standardoutput

Time Limit: 7 seconds

Memory Limit: MB

baaaam! Another deadly gas bomb explodes in Manhattan ' Sunderworld. Rats has taken over the sewerage and the city Council are doing everything to get the rat population under control.

As you know, Manhattanis organized in a regular fashion with streets and avenues arranged like Arectangular grid. Waste water drains run beneath the streets in the samearrangement and the rats has always set up their nests below street Intersections. The only viable method to extinguish them are to use gas bombslike the one which have just exploded. However, gas bombs is not only dangerousfor rats. The skyscrapers above the explosion point has to being evacuated inadvance and so the point of rats attack must be chosen ver Y carefully.

The gas bombs used is built by a company called Americancatastrophe Management (ACM) and they is sold under the heading of "Smart rat gas". They is smart because-when fired-the gas spreads in a rectangular fashion through the under street canals. Thestrength of a gas bomb are given by a number d which specifies the rectangular "radius" of the gas diffusion area. For example, Figure 2 showswhat happens if a bomb with D = 1 explodes.

The problem

The area of interest consists of a discrete grid of 1025x1025 fields. Rat Exterminator Scouts had given a detailed report onwhere rat populations of different sizes had built their nests. You were Givena gas bomb with strength D and your task was to find a explosion location forthis gas bomb which extinguishes The largest number of rats.

The best position are determined by the following criteria:

the sum of all rats population sizes within thediffusion area of the gas bomb (given by D) is maximal.

If there is more than one of the these best positionsthen the location with the "minimal" position would be chosen. Positions is ordered first by their X coordinate and second by their ycoordinate.

Formally, given a location (x1, y1) on the grid, a point (x2, y2) are within the diffusion area of a gas bomb with strength D if thefollowing equation holds:

Max (ABS (X2-X1), ABS (Y2-Y1)) <= D

Input

The first line contains the number of scenarios in Theinput.

For each scenario, the first line contains the strength d of the gas Bombin the scenario (1<= D <= 50). The secondline contains the number n (1<= n <= 20000) of ratpopulations. Then for every rat population follows a line containing threeintegers separated by spaces for the position (x, y) and "siz E "I of thepopulation (1 <= i <= 255). It isguaranteed that position coordinates was valid (i.e., in the range between 0and 1024x768) and no position is given more t Han once.

Output

For every problem print a line containing the X and ycoordinate of the chosen location for the gas bomb, followed by the S Um of Therat population sizes which would be extinguished. The three numbers must beseparated by a space.

Sample Input

1

1

2

4 4 10

6 6 20

Sample Output

5 5 30

For each found bomb to find out the total number of kills within its scope, a new sequence of numbers indicates the number of mice that should be killed at that point.

Compared with the original mouse, check out the number of the last mice killed.

#include <stdio.h>#include<string.h>inta[1050][1050];intMain () {intt,d,n,i,j,k,m,x,y,p; scanf ("%d",&t);  while(t--) {memset (A,0,sizeof(a)); scanf ("%d%d",&d,&N);  for(i=0; i<n;i++) {scanf ("%d%d%d",&x,&y,&p);  for(K= (x-d>0)? (x-d):0); K<= (x+d>=1030)?1030:(x+d)); k++)                 for(M= (y-d>0)? (y-d):0); M<= (y+d>=1030)?1030:(y+d)); m++) A[k][m]+=p; }        intmax=0, Mx,my;  for(i=0;i<1030; i++)             for(j=0;j<1030; j + +)                if(a[i][j]>max) {Max=A[i][j]; MX=i; My=J; } printf ("%d%d%d\n", Mx,my,max); }    return 0;}

UVA 10360 Rat Attack

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.