1709: [Usaco2007 oct]super Paintball Super Pinball time limit:5 Sec Memory limit:64 MB
submit:352 solved:275
[Submit] [Status] [Discuss] Description
Cows have recently bought a simulated paintball device from the famous cow toy maker Tycow (quasi in live CS). Bessie them to play the game the lawn is divided into a matrix of n * N (1 <= n<= 100) units, along with a list of her K (1 <= k <= 100,000) opponents on the grass position. And then she came to you with this watch, hoping you could help her figure out a piece of data. In this game, a cow can shoot a bullet in one of 8 directions with a marble gun. The 8 directions are: North, south, east, due west, and the 45° angle sandwiched between the 4 positive directions: Northeast, Southeast, northwest, southwest. Bessie you tell her how many options she would have if she wanted to stand on a grid of all the opponents she could shoot at. Of course, Bessie could stand on the same grid as one of her opponents, and in that case, you could think that Bessie could shoot her opponent in the same lattice.
Input
* Line 1th: 2 integers separated by a space: N and K
* 2nd. K+1 Line: Line i+1 with 2 spaces separated by the integer R_i and c_i, describes the position of the first cow, indicating that she is standing in the R_i line, section c_i
Output
* Line 1th: Outputs 1 integers, indicating the number of squares that can be selected if Bessie.
Sample Input4 3
2 1
2 3
4 1
Input Description:
The ranch was divided into 4 rows and 4 columns. Bessie's station must ensure she can shoot at the station (2,1), (2,3)
and (4,1) of cows:
. . . .
C. C.
. . . . <---The location of the cows
C...
Sample Output5
Output Description:
Bessie can choose to stand in one of the following squares: (2,1), (2,3), (3,2), (4,1),
and (4,3). In the bottom right, the Bessie with other cows are marked as ' * ':
. . . . . . . .
B. B. ---\ * . * .
. B. . ---/ . B. .
B. B. * . BI see this problem data range is <=100, so violent enumeration, first put the point of the cow with the a[i][j] value + +, and then each point of the eight direction all add one, and then enumerate a[i][j]>1 points, a[i][j]--,ans++, if ans=k, sum++; The value of the last output sum can be. But write it out after CE. The program does not run properly .... Later thought, a point that can attack all cows, will inevitably be attacked by all other cows, so you can read into a point [x][y], the point where the line h[x], column Lie[y], positive/secondary diagonal c[x-y+n],d[x+y]++,a[x][y]++ Then another N*n enumeration, if h[x]+lie[y]+c[x-y+n]+d[x+y]-3xa[x][y]==k, indicates that this point can attack all cows, sum++. (Here is a question to consider, depending on whether there is a cow at each point, the judgment is different; if there is no cow, this point can be attacked must be K, that is h[x]+lie[y]+c[x-y+n]+d[x+y]==k; if there is a cow, This point can be attacked to the k-1 at this time we set the a[x][y]++ to come in handy, h[x]+lie[y]+c[x-y+n]+d[x+y], for [X][y] added 4, minus 3, plus by the other k-1 points covered, finally still be k points covered! Or is he too young. Code:
1#include <cstdio>2#include <iostream>3#include <cstring>4 inta[1001],b[1001],c[1001],d[1001],bei[ +][ +];5 using namespacestd;6 intMain ()7 {8 intn,m,x,y,sum=0;9Cin>>n>>m;Tenmemset (bei,0,sizeof(bei)); One for(intI=1; i<=m;++i) A { -scanf"%d%d",&x,&y); -a[x]++;b[y]++;c[x-y+n]++;d [x+y]++; thebei[x][y]++; - } - for(intI=1; i<=n;++i) - for(intj=1; j<=n;++j) + if(a[i]+b[j]+c[i-j+n]+d[i+j]-3*BEI[I][J]==M) sum++; -cout<<sum; + return 0; A}
View Code
BZOJ1709 Super Marbles