UVA 10360 Rat Attack

Rat Attack

Input: standard input

Output: standardoutput

Time Limit: 7 seconds

Memory Limit: 32 MB

Baaaam! Another deadly gas bomb explodes in Manhattan’sunderworld. Rats have taken over the sewerage and the city council is 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 have always set up their nests below streetintersections. The only viable method to extinguish them is to use gas bombslike the one which has just exploded. However, gas bombs are not only dangerousfor rats. The skyscrapers above the explosion point have to be evacuated inadvance and so the point of rat attack must be chosen very carefully.

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

The Problem

The area of interest consists of a discrete grid of 1025× 1025 fields. Rat exterminator scouts have given a detailed report onwhere rat populations of different sizes have built their nests. You are givena gas bomb with strength d and your task is to find an explosion location forthis gas bomb which extinguishes the largest number of rats.

The best position is determined by the following criteria:

• The sum of all rat population sizes within thediffusion area of the gas bomb (given by d) is maximal.

• If there is more than one of these best positionsthen the location with the “minimal” position will be chosen.Positions are ordered first by their x coordinate and second by their ycoordinate.

Formally, given a location (x1, y1) on the grid, a point(x2, y2) is 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 “size” i of thepopulation (1 <= i <= 255). It isguaranteed that position coordinates are valid (i.e., in the range between 0and 1024) and no position is given more than once.

Output

For every problem print a line containing the x and ycoordinate of the chosen location for the gas bomb, followed by the sum of therat population sizes which will 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

对于每个找到的炸弹找出其作用范围内杀死的总数,构成新的数列表明在该处应该被杀死的老鼠的数量。

与原来的老鼠存在数列比较,核对出最后杀死的老鼠数量。

#include<stdio.h>
#include<string.h>
int a[1050][1050];
int main(){
    int t,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;
        }
        int max=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;
}
时间: 2024-10-25 17:07:13

UVA 10360 Rat Attack的相关文章

uva 11195 Another queen (用状态压缩解决N后问题)

题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2136 Problem A Another n-Queen Problem I guess the n-queen problem is known by every person who has studied backtracking. In this problem you s

UVA 11292 Dragon of Loowater(简单贪心)

Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major problem. The shores of Rellau Creek in central Loowater had always been a prime breeding ground for geese. Due to the lack of predato

uva 11292

A - Dragon of Loowater Time Limit:1000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Practice UVA 11292 Appoint description:  System Crawler  (2014-11-26) Description Problem C: The Dragon of Loowater Once upon a time, in the K

UVA之11292 Dragon of Loowater

Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major problem. The shores of Rellau Creek in central Loowater had always been a prime breeding ground for geese. Due to the lack of predato

UVA - 11986 Save from Radiation

Description J Save from Radiation Most of you are aware of Nuclear Power Plant Explosion at Fukushima after devastating earth quake and tsunami. Many people in Bangladesh were seen to be concerned with radiation. The message says: BBC Flash news: Jap

·UVa」 11292 - Dragon of Loowater( 贪心 )

Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major problem. The shores of Rellau Creek in central Loowater had always been a prime breeding ground for geese. Due to the lack of predato

uva 567 - Risk

 Risk  Risk is a board game in which several opposing players attempt to conquer the world. The gameboard consists of a world map broken up into hypothetical countries. During a player's turn, armies stationed in one country are only allowed to attac

UVA它11292 - Dragon of Loowater

Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major problem. The shores of Rellau Creek in central Loowater had always been a prime breeding ground for geese. Due to the lack of predato

uva 11825 Hackers&#39; Crackdown(状态压缩DP)

Hackers' Crackdown Input: Standard Input Output: Standard Output   Miracle Corporations has a number of system services running in a distributed computer system which is a prime target for hackers. The system is basically a set of N computer nodes wi