daily pastebin goal
75%
SHARE
TWEET

Untitled

a guest Dec 18th, 2018 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <set>
  2. #include <bitset>
  3. #include <queue>
  4. #include <deque>
  5. #include <stack>
  6. #include <sstream>
  7. #include <iostream>
  8. #include <iomanip>
  9. #include <cstdio>
  10. #include <cstdlib>
  11. #include <cmath>
  12. #include <ctime>
  13. #include <cstring>
  14. #include <string>
  15. #include <cassert>
  16. #include <vector>
  17. #include <list>
  18. #include <map>
  19. #include <algorithm>
  20. #include <functional>
  21. #include <numeric>
  22. #include <utility>
  23.  
  24. // DEFINE
  25. #define FOR(i,a,b)     for (int i=(a),_b=(b); i<_b; i++)
  26. #define RFOR(i,b,a)    for (int i=(b)-1,_a=(a); i>=_a; i--)
  27. #define RESET(a,b)      memset((a),(b),sizeof(a))
  28. #define fi              first
  29. #define se              second
  30. #define foreach(i, c)   for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
  31.  
  32. //
  33. using namespace std;
  34. typedef vector <int> vi;
  35. typedef vector <vi> vvi;
  36. typedef pair <int, int> ii;
  37. typedef vector <ii> vii;
  38. typedef vector <string> vs;
  39. typedef long long int64; //NOTES:int64
  40. typedef unsigned long long uint64; //NOTES:uint64
  41. typedef unsigned uint;
  42. const double pi = acos(-1.0); //NOTES:pi
  43. const double eps = 1e-11; //NOTES:eps
  44. const int MAXI = 0x7fffffff;
  45. int in() {
  46.     int x = 0, c;
  47.     for (; (uint)((c = getchar()) - '0') >= 10; ) { if (c == '-') return -in(); if (!~c) throw ~0; }
  48.     do { x = (x << 3) + (x << 1) + (c - '0'); } while ((uint)((c = getchar()) - '0') < 10);
  49.     return x;
  50. }
  51. // CODE
  52. int a[1000][1000];
  53. pair<int,int> re;
  54. bool quad(int l, int r, int u, int d, int x)
  55. {
  56.     if(l > r || u > d)
  57.         return false;
  58.     if(x > a[d][r] || x < a[u][l])
  59.         return false;
  60.     int row, col;
  61.     row = (u+d)/2;
  62.     col = (l+r)/2;
  63.     if(a[row][col] == x)
  64.     {
  65.         re.fi = row;
  66.         re.se = col;
  67.         cout << "a[" << row << "][" << col << "] = " << a[row][col] << endl;
  68.         return true;
  69.     }
  70.     else
  71.         if(l == r && u == d)
  72.             return false;
  73.     if(x > a[row][col])
  74.         return quad(col+1,r,u,row,x) || quad(l,col,row+1,d,x) || quad(col+1,r,row+1,d,x);
  75.     else   
  76.         return quad(l,col,u,row,x) || quad(col+1,r,u,row,x) || quad(l,col,row+1,d,x);
  77. }
  78. int main(int argc, char *argv[])
  79. {
  80.     int n, x;
  81.     cin >> n;
  82.     FOR(i,0,n)
  83.         FOR(j,0,n)
  84.             cin >> a[i][j];
  85.     cin >> x;
  86.     if(quad(0,n-1,0,n-1,x))
  87.         cout << "YES";
  88.     else
  89.         cout << "NOT FOUND!";
  90.     return 0;
  91. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top