Рабочий стол > DL Руководство пользователя > ... > Быстрое погружение в язык C++ > Очередь cell > Information > Сравнить страницу
Очередь cell Войти | Зарегистрироваться   Просмотр версии для печати текущей страницы.

Версия 1 Egor
на Oct 09, 2016 11:26.


 
в сравнении с
Ключ
Эти линии были удалены. Это слово было удалено.
Эти линии были добавлены. Это слово было добавлено.

Просмотр истории страницы


Есть 4 изменений. Просмотреть первое изменение .

 {code:title=cell1.cpp\|borderStyle=solid}\#include <bits/stdc++.h>
  {code:title=cell1.cpp\|borderStyle=solid}
 #include <bits/stdc++.h>
 using namespace std;
  
 struct moves
  {
  int x;
  int y;
  };
 queue <moves> MQue;
  
 bool Marked[8][8];
  
 void StartProcess()
  {
  for (int i=0; i<8; i++)
  for (int j=0; j<8; j++) Marked[i][j]=false;
  int n;
  cin >> n;
  for (int i=0; i<n; i++)
  {
  int x,y;
  cin >> x >> y;
  Marked[x-1][y-1]=true;
  }
  }
  
 bool Found(int &x, int &y)
  {
  for (int i=0; i<8; i++)
  for (int j=0; j<8; j++)
  if (not Marked[i][j])
  { x=i; y=j; return true;};
  return false;
  }
  
 void PutAll(moves CurrMove)
  {
  int steps[4][2] = {{0,-1},{0,1},{-1,0},{1,0}};
  for (int i=0; i<4; i++)
  {
  moves Cur;
  Cur.x=CurrMove.x+steps[i][0];
  Cur.y=CurrMove.y+steps[i][1];
  if ((Cur.x>=0) && (Cur.x<8) &&
  (Cur.y>=0) && (Cur.y<8) &&
  (not Marked[Cur.x][Cur.y]))
  {MQue.push(Cur); Marked[Cur.x][Cur.y]=true;};
  }
  }
  
 int main()
 {
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  StartProcess();
  int PieceNumber=0,x,y;
  while (Found(x,y))
  {
  PieceNumber++;
  moves StartMove; StartMove.x=x; StartMove.y=y;
  MQue.push(StartMove); Marked[x][y]=true;
  while (not MQue.empty())
  {
  moves CurrMove=MQue.front(); MQue.pop();
  PutAll(CurrMove);
  }
  }
cout << PieceNumber; }{code}
  cout << PieceNumber; }
 {code}\\
 {code:title=cell2.cpp\|borderStyle=solid}
 #include <bits/stdc++.h>using namespace std;
  
&nbsp;{code:title=cell2.cpp\|borderStyle=solid}\#include <bits/stdc++.h>using namespace std;
  
 queue <int> X,Y; // Две очереди по одному числу
  
 bool Marked[8][8];
  
 void StartProcess()
  {
  for (int i=0; i<8; i++)
  for (int j=0; j<8; j++) Marked[i][j]=false;
  int n;
  cin >> n;
  for (int i=0; i<n; i++)
  {
  int x,y;
  cin >> x >> y;
  Marked[x-1][y-1]=true;
  }
  }
  
 bool Found(int &x, int &y)
  {
  for (int i=0; i<8; i++)
  for (int j=0; j<8; j++)
  if (not Marked[i][j])
  { x=i; y=j; return true;};
  return false;
  }
  
 void PutAll(int x, int y)
  {
  int steps[4][2] = {{0,-1},{0,1},{-1,0},{1,0}};
  for (int i=0; i<4; i++)
  {
  int Cx=x+steps[i][0];
  int Cy=y+steps[i][1];
  if ((Cx>=0) && (Cx<8) &&
  (Cy>=0) && (Cy<8) &&
  (not Marked[Cx][Cy]))
  {X.push(Cx); Y.push(Cy); Marked[Cx][Cy]=true;};
  }
  }
  
 int main()
 {
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  StartProcess();
  int PieceNumber=0,x,y;
  while (Found(x,y))
  {
  PieceNumber++;
  X.push(x); Y.push(y); Marked[x][y]=true;
  while (not X.empty())
  {
  x=X.front(); X.pop();
  y=Y.front(); Y.pop();
  PutAll(x,y);
  }
  }
  cout << PieceNumber; }{code}
   cout << PieceNumber; }
 {code}\\
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: http://www.atlassian.com/software/confluence Build:#2.6.1 916) - Ошибка/новая особенность - Свяжитесь с Администраторами