[Valley] Los wireless network transmitter site

(Original title Portal)

Thinking

Konjac after seeing the data range This question indicates shivering, but after Qiaowan LowLow the Code she discovered the AC? ! ! Well, this question is bluffing range data, calculate the toilet paper out can be found in O (n- . 4 ) time complexity can be AC, this limited capacity of konjac brain, showing no idea can not read O (n- 2 ) of the algorithm,A complete run ~~~ C

This question is not out of bounds for the array, a negative index, can be solved by Japanese sentence, but the present approach uses a konjac more violent: directly from the cross [21] [21] starts storing (n <= 20), did the used space set to 0, so if you access subscript less than 21 can get but that is 0(Genius idea, fast applause)

Then, a heavy cycle 2 to try every possible location, and then a double-nested loop to calculate the location of each of the "value", then compared with the maximum value, if equal to the maximum, then that maximum for Selecting more than one of the largest recorded number of siting program variable sum ++, before if more than the maximum, indicating that all of the largest schemes are false, there is a greater, the sum owned by 1, and the maximum value set for the current value.

Finally, the output can be.

The rest is water code QAQ.

Code

#include<iostream>
using namespace std;
int x,y,d,n,gkmax,num,sum=1,cross[170][170];
int main()
{
    cin>>d>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>x>>y>>cross[x+20][y+20];
    }
    for(int i=20;i<=148;i++)
        for(int j=20;j<=148;j++)
        {
            for(int m=i-d;m<=i+d;m++)
                for(int k=j-d;k<=j+d;k++)    
                    num+=cross[m][k];
            if(gkmax==num)
            {
                sum++;
            }
            if(gkmax<num)
            {    
                sum=1;
            }
            gkmax=max(gkmax,num);
            num=0;
        }
    cout<<sum<<" "<<gkmax;
    return 0;
}

Guess you like

Origin www.cnblogs.com/gongdakai/p/11027063.html