Simulation [NOIP2014] Wireless network emitter location

Source: Internet
Author: User
DescriptionWith the increasing popularity of smartphones, there is a growing demand for wireless networks. A city decided to cover the public places in the city wireless network.
Suppose the layout of the city is a grid of strictly parallel 129 things to the streets and 129 north-south streets, and the distance between adjacent parallel streets is a constant value of 1. Things to the street from north to south, sequentially numbered 0,1,2 ... 128, north-south Street from west to east, sequentially numbered 0,1,2 ... 128.
The intersection of the east and the west into the street and the north-South Street, the coordinates of the intersection of the north-south Street numbered X and the number y to the street are (x, y). There is a certain number of public places at some intersections.
As a result of government finances, only one large wireless network transmitter can be installed. The transmission range of the wireless network transmitter is a square with the 2*d of the center and the edge length. The propagation range includes the square boundary.
For example, the following figure is a map of the coverage of a wireless network emitter with d = 1.

Now the government departments are ready to install a wireless network transmitter with a transmission parameter D, I hope you help them to find a suitable installation location in the city, so that the most public places covered. Input FormatThe first line contains an integer d that represents the propagation distance of the wireless network emitter.
The second line contains an integer n, indicating the number of intersections with public places.
Next n rows, each row gives three integers x, y, K, separated by a space, respectively, representing the coordinates of the intersection (x, y) and the number of public places at the intersection. The same coordinates are given only once.
Output format OutputA row, containing two integers, separated by a space, indicating the number of installation locations that can cover the most public places, and the maximum number of public places that can be covered. Sample Input1
2
4 4 10
6 6 20 Sample Output1 30
var
 t,d,max,sum,linshi:longint;
 W:array[0..128,0..128]of Longint;
 I,j,m,n:longint;
 X,y,k:longint;
Begin
 Readln (d);
 READLN (t);
 For I:=1 to T do
  begin
   Readln (x,y,k);
   Inc (W[X,Y],K);
  End;
 Max:=-1; sum:=0;
 For i:=0 to + do for j:=0 to + do
   begin
    linshi:=0;
    For m:=-d to D does for
     n:=-d to D does
      if (i+m>=0) and (j+n>=0) and (i+m<=128) and (j+n<=128) then
      Inc (Linshi,w[i+m,j+n]);
    If Linshi>max then
    begin Max:=linshi; sum:=1, end
    Else
     if (Linshi=max) and (max<>0)
     Then Inc (sum);
   End;
 Writeln (Sum, ", max);
End.

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.