作者:iloveyoumuch18 | 来源:互联网 | 2023-05-17 14:52
队列的定义队列是一种容器适配器,专门设计用于在FIFO上下文(先进先出)中操作,其中元素插入容器的一端并从另一端提取。队列被实现为容器适配器,它是使用特定容器类的封装对象作为其基础
- 队列的定义
队列是一种容器适配器,专门设计用于在FIFO上下文(先进先出)中操作,其中元素插入容器的一端并从另一端提取。 队列被实现为容器适配器,它是使用特定容器类的封装对象作为其基础容器的类,提供一组特定的成员函数来访问其元素。 元素被推入特定容器的“背部”并从其“前”弹出。
- 成员函数
Member functions
-
(constructor)
-
Construct queue
(public member function )
-
empty
-
Test whether container is empty
(public member function )
-
size
-
Return size
(public member function )
-
front
-
Access next element
(public member function )
-
back
-
Access last element
(public member function )
-
push
-
Insert element
(public member function )
-
emplace
-
Construct and insert element
(public member function )
-
pop
-
Remove next element
(public member function )
-
swap
-
Swap contents
(public member function )
Non-member function overloads
-
relational operators
-
Relational operators for queue
(function )
-
swap (queue)
-
Exchange contents of queues
(public member function )
Non-member class specializations
-
uses_allocator
-
Uses allocator for queue
(class template )
#include
#include
#include
using namespace std;
int main()
{
queue<int> myqueue;
int sum=0;
for (int i = 1; i <= 10; i++) myqueue.push(i);
cout <
10
total: 55
- size: 0 - size: 5 - size: 4 myqueue contains:
First sentence
Second sentence
size of foo: 2
size of bar: 3
Press any key to continue . . .
#include
#include
using namespace std;
#pragma warning(disable:4996)
typedef struct
{
int x, y, z;
}nodes;
int att[1287][129][61];
bool visit[1287][129][61];
int m, n, l, t;
bool judge(int x, int y, int z)
{
if (x<0 || x>=m || y<0 || y>=n || z<0 || z>= l)return false;
if (att[x][y][z] == 0 || visit[x][y][z] == 1)return false;
return true;
}
int fx[6] = { 1,0,0,-1,0,0 };
int fy[6] = { 0,1,0,0,-1,0 };
int fz[6] = { 0,0,1,0,0,-1 };
int bfs(int x, int y, int z)
{
int inc = 0;
int tempx, tempy, tempz;
nodes p;
p.x = x; p.y = y; p.z = z;
queue q;
q.push(p);
nodes temp;
visit[x][y][z] = 1;
while (!q.empty())
{
temp = q.front();
q.pop();
++inc;
for (int i = 0; i <6; ++i)
{
tempx = temp.x + fx[i];
tempy = temp.y + fy[i];
tempz = temp.z + fz[i];
if (judge(tempx, tempy, tempz))
{
visit[tempx][tempy][tempz] = 1;
p.x = tempx; p.y = tempy; p.z = tempz;
q.push(p);
}
}
}
if (inc >= t)
return inc;
else
return 0;
}
int main()
{
scanf("%d %d %d %d", &m, &n, &l, &t);
int i, j, k;
for (k = 0; k for (i = 0; i for (j = 0; j scanf("%d", &att[i][j][k]);
int result = 0;
for (k = 0; k for (i = 0; i for (j = 0; j if(att[i][j][k]==1&&visit[i][j][k]==0)
result += bfs(i, j, k);
printf("%d", result);
system("pause");
return 0;
}