Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.82 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define INF 1e9
  5. #define pb push_back
  6. #define mp make_pair
  7. #define nl '\n'
  8.  
  9. typedef long long ll;
  10. typedef vector<int> vi;
  11. typedef pair<int,int> ii;
  12. typedef vector<ii> vii;
  13.  
  14. int grid[105][105];
  15.  
  16. int sol[105][105];
  17.  
  18. int canPlace(int x,int y){
  19.     if(grid[x][y]==1){
  20.         return 1;
  21.     }
  22.     else return 0;
  23. }
  24.  
  25. int search(int x,int y,int k){
  26.  
  27.     int count=0,up=0,down=0,left=0,right=0;
  28.     for(int i=0;i<k;i++){
  29.         cout << "loop #" << i << nl;
  30.         cout << "checking " << x+1 << " " << y+i+1 << " is " << grid[x][y+i] << nl;
  31.         if(grid[x][y+i]==1){
  32.             up++;
  33.            
  34.         }
  35.         cout << "up is now " << up << nl;
  36.         cout << "checking " << x+1 << " " << y-i+1 << " " << grid[x][y-i] << nl;
  37.         if(grid[x][y-i]==1){
  38.            
  39.             down++;
  40.            
  41.         }
  42.         cout << "down is now " << down << nl;
  43.         cout << "checking " << x+i+1<< " " << y+1 << " " << grid[x+i][y] << nl;
  44.         if(grid[x+i][y]==1){
  45.            
  46.             right++;
  47.            
  48.         }
  49.         cout << "right is now " << right << nl;
  50.         cout << "checking " << x-i+1 << " " << y+1 << " " << grid[x-i][y] << nl;
  51.         if(grid[x-i][y]==1){
  52.            
  53.             left++;
  54.            
  55.         }
  56.         cout << "left is now " << left << nl;
  57.     }
  58.     if(up==k) count++;
  59.     if(down==k) count++;
  60.     if(left==k) count++;
  61.     if(right==k) count++;
  62.     cout << count << nl;
  63.     return count;
  64.  
  65. }
  66.  
  67. int main(){
  68.     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  69.  
  70.     int n,k,x=1,y=1,max=0;
  71.     char tmp;
  72.  
  73.     cin >> n >> k;
  74.  
  75.     for(int i=0;i<n;i++){
  76.         for(int j=0;j<n;j++){
  77.             cin >> tmp;
  78.             if(tmp=='#') grid[i][j]=-1;
  79.             else grid[i][j]=1;
  80.         }
  81.     }
  82.  
  83.     for(int i=0;i<n;i++){
  84.         for(int j=0;j<n;j++){
  85.             if(grid[i][j]==0) continue;
  86.             sol[i][j]=search(i,j,k);
  87.         }
  88.     }
  89.     for(int i=0;i<n;i++){
  90.         for(int j=0;j<n;j++){
  91.             if(sol[i][j]>max){
  92.                 x=i+1;
  93.                 y=j+1;
  94.                 max=sol[i][j];
  95.             }
  96.         }
  97.     }
  98.     cout << x << " " << y;
  99.  
  100.  
  101.     return 0;
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement