Advertisement
Guest User

F

a guest
Sep 16th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.70 KB | None | 0 0
  1.    #include <iostream>
  2.     #include <vector>
  3.  
  4.     using namespace std;
  5.  
  6.     struct Point{
  7.             unsigned long long xx;
  8.             unsigned long long yy;
  9.     };
  10.  
  11.  
  12.     int main(){
  13.             std::ios::sync_with_stdio(false);
  14.             unsigned long long W, H, N;
  15.             cin >> W >> H >> N;
  16.             unsigned long long size = W * H;
  17.             if (size > N * 5){
  18.                 cout << "No" << endl;
  19.                 return 0;
  20.             }
  21.  
  22.             unsigned long long pointsCount = 0;
  23.             vector<vector<unsigned long>> polotno(W);
  24.             for (unsigned long i = 0; i < W; i++){
  25.                 polotno[i].assign(H, 0);
  26.             }
  27.  
  28.             for (unsigned long i = 0; i < N; i++){
  29.                 if ((N - i + 1) * 5 < (size - pointsCount + 1)){
  30.                     cout << "No";
  31.                     return 0;
  32.                 }
  33.                     long long x, y;
  34.                     cin >> x >> y;
  35.                     x--;
  36.                     y--;
  37.                     vector<Point> points;
  38.                     Point p;
  39.                     if ((x >= 0) && (x < W) && (y >= 0) && (y < H)){
  40.                             p.xx = x;
  41.                             p.yy = y;
  42.                             points.push_back(p);
  43.                     }
  44.  
  45.                     if ((x - 1 >= 0) && (x - 1 < W) && (y >= 0) && (y < H)){
  46.                             p.xx = x - 1;
  47.                             p.yy = y;
  48.                             points.push_back(p);
  49.                     }
  50.  
  51.                     if ((x >= 0) && (x < W) && (y - 1 >= 0) && (y - 1 < H)){
  52.                             p.xx = x;
  53.                             p.yy = y - 1;
  54.                             points.push_back(p);
  55.                     }
  56.  
  57.                     if ((x + 1 >= 0) && (x + 1 < W) && (y >= 0) && (y < H)){
  58.                         p.xx = x + 1;
  59.                         p.yy = y;
  60.                         points.push_back(p);
  61.                     }
  62.  
  63.                     if ((x >= 0) && (x < W) && (y + 1 >= 0) && (y + 1 < H)){
  64.                         p.xx = x;
  65.                         p.yy = y + 1;
  66.                         points.push_back(p);
  67.                     }
  68.  
  69.                     for (auto& element : points) {
  70.                         if (polotno[element.xx][element.yy] == 0) { //так как считаем с 0 массив, а клетки с 1
  71.                             polotno[element.xx][element.yy] = 1;
  72.                             pointsCount++;
  73.                         }
  74.                     }
  75.             }
  76.  
  77.         if (pointsCount == size){
  78.             cout << "Yes" << endl;
  79.         } else {
  80.             cout << "No" << endl;
  81.         }
  82.         return 0;
  83.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement