Advertisement
Guest User

Untitled

a guest
Apr 18th, 2015
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. #include <cstdio>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. #define MAX 1003
  7.  
  8.  
  9. int main()
  10. {
  11. int mat[MAX][MAX], east[MAX][MAX], south[MAX][MAX], west[MAX][MAX], north[MAX][MAX];
  12. int n, k, i, j, count = 0;
  13. cin >> n >> k;
  14.  
  15. for(i=0; i<n; i++)
  16. for(j=0; j<n; j++)
  17. mat[i][j] = east[i][j] = south[i][j] = west[i][j] = north[i][j] = 0;
  18.  
  19. for(i=0; i<k; i++){
  20. cin >> i >> j;
  21. mat[i][j] = 1;
  22. }
  23.  
  24. //west
  25. for(i=0; i<n; i++){
  26. for(j=1; j<n; j++){
  27. west[i][j] = west[i][j-1] + mat[i][j-1];
  28.  
  29. //north
  30. for(i=1; i<n; i++){
  31. for(j=0; j<n; j++){
  32. north[i][j] = north[i-1][j] + mat[i-1][j];
  33.  
  34. //south
  35. for(i=n-2; i>=0; i--){
  36. for(j=0; j<n; j++){
  37. south[i][j] = south[i+1][j] + mat[i+1][j];
  38.  
  39. //east
  40. for(i=0; i<n; i++){
  41. for(j=n-2; j>=0; j--)
  42. east[i][j] = east[i][j+1] + mat[i][j+1];
  43.  
  44. for(i=0; i<n; i++){
  45. for(j=0; j<n; j++){
  46. if(mat[i][j] != 0 && west[i][j] > 0 && south[i][j] > 0 && north[i][j] > 0 && east[i][j] > 0)
  47. count++;
  48. }
  49. }
  50. cout << count << endl;
  51. return 0;
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement