本文整理汇总了C++中queue::empty方法的典型用法代码示例。如果您正苦于以下问题:C++ queue::empty方法的具体用法?C++ queue::empty怎么用?C++ queue::empty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类queue
的用法示例。
在下文中一共展示了queue::empty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: bfs
int bfs(){
int i,j,k;
while(!q.empty()){
sqr sq=q.front();
q.pop();
//判断是否到达目标
bool flag = false;
for(i=0;i<3;i++){
for(j=0;j<3;j++){
if(sq.a[i][j]!=t[i][j]){
flag = true;
}
}
}
if(!flag)return sq.deep;
//移动
for(i=0;i<3;i++){
for(j=0;j<3;j++){
if(sq.a[i][j]==0){
for(k=0;k<4;k++){
int x1=i,y1=j,x2=i+d[k][0],y2=j+d[k][1];
if(!check(x2,y2))continue;
swap(sq.a[x1][y1],sq.a[x2][y2]);
sq.deep++;
q.push(sq);
swap(sq.a[x1][y1],sq.a[x2][y2]);
sq.deep--;
}
}
}
}
}
return INF;
}
示例2: main
int main()
{
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
scanf("%d",&a[j].val);
a[j].id=j;
}
sort(a,a+m,cmp);
for(int j=0;j<m;j++){
if(a[j].val==-1) continue;
if(!j||a[j].val!=a[j-1].val) cnt++;
add(a[j].id,m+cnt+1);
add(m+cnt,a[j].id);
}
cnt++;
}
for(int i=0;i<m+cnt;i++)
if(!in[i]) que.push(i);
while(!que.empty()){
int u=que.front();que.pop();
if(u<m)
ans[tot++]=u;
for(int i=0;i<edge[u].size();i++){
int v=edge[u][i];
in[v]--;
if(!in[v])
que.push(v);
}
}
if(tot<m) puts("-1");
else{
for(int i=0;i<m;i++)
cout<<ans[i]+1<<(i==m-1?"\n":" ");
}
return 0;
}
示例3: Work
void Work()
{
for (int i = 1; i <= N; i++)
dis[i] = INF;
memset(use, 0, sizeof(use));
dis[X] = 0;
use[X] = true;
Q.push(X);
while (!Q.empty())
{
int v = Q.front();
Q.pop();
for (int i = 1; i <= N; i++)
{
if (Left[v] >= Map[v][i] && dis[v] < dis[i])
{
dis[i] = dis[v];
Left[i] = Left[v] - Map[v][i];
if (!use[i])
{
use[i] = true;
Q.push(i);
}
}
else if (T[v] >= Map[v][i] && dis[v] + C[v] < dis[i])
{
dis[i] = dis[v] + C[v];
Left[i] = T[v] - Map[v][i];
if (!use[i])
{
use[i] = true;
Q.push(i);
}
}
}
use[v] = false;
}
}
示例4: bfs
void HexBoard::bfs(const ip vertex)
{
Q.push(vertex);
PlayerColor present_player_color;
while(!Q.empty())
{
ip v=Q.front();
int node=v.first;
Q.pop();
markedbfs[node]=presentPlayer;
for(int i=0;i<edge[node].size();++i)
{
int j=edge[node][i];
int row_j=row_val(j);
int column_j=column_val(j);
if(presentPlayer==1) present_player_color=player1color;
else present_player_color=player2color;
if(markedbfs[j]==-1 && vertices[row_j][column_j].second==present_player_color)
{
Q.push(vertices[row_j][column_j]);
}
}
}
cout<<endl;
//game ends only if same player is on both virtual nodes
if(markedbfs[WEST]==presentPlayer && markedbfs[EAST]==presentPlayer && present_player_color==PlayerColor::BLUE) endgame();
if(markedbfs[NORTH]==presentPlayer && markedbfs[SOUTH]==presentPlayer && present_player_color==PlayerColor::RED) endgame();
//reset the markedbfs array
markedbfs=(vector<int>(SIZE*SIZE+5,-1));
}
示例5: main
int main()
{
int i,n,m,q,ta,tb,sx,sy;
scanf("%d %d %d",&n,&m,&q);
for(i=0;i<m;i++) {scanf("%d %d",&ta,&tb); f[ta][tb]=-1;}
scanf("%d %d",&sx,&sy);
inp.x=sx; inp.y=sy; inp.z=1;
qu.push(inp);
while(not qu.empty())
{
inp=qu.front(); qu.pop();
if(inp.x<1||inp.x>n||inp.y<1||inp.y>n||f[inp.x][inp.y]!=0) continue;
else
{
if(inp.z>ma) ma=inp.z;
ans[inp.z]++;
f[inp.x][inp.y]=inp.z;
sx=inp.x; sy=inp.y; ta=inp.z;
inp.x=sx-1; inp.y=sy; inp.z=ta+1; qu.push(inp);
inp.x=sx+1; inp.y=sy; inp.z=ta+1; qu.push(inp);
inp.x=sx; inp.y=sy-1; inp.z=ta+1; qu.push(inp);
inp.x=sx; inp.y=sy+1; inp.z=ta+1; qu.push(inp);
}
}
/*for(i=1;i<=n;i++)
{
for(tb=1;tb<=n;tb++) printf("%d ",f[i][tb]);
printf("\n");
}*/
for(i=1;i<=ma;i++) ans[i]+=ans[i-1];
for(i=0;i<q;i++)
{
scanf("%d",&tb);
if(tb>=ma) printf("%d\n",ans[ma]);
else printf("%d\n",ans[tb+1]);
}
return 0;
}
示例6: pop
// Removes the element on top of the stack.
void pop() {
if(q1.size() == 1)
{
q1.pop();
}
else{
while(q1.size() != 1)
{
q2.push(q1.front());
q1.pop();
}
q1.pop();
while(!q2.empty())
{
q1.push(q2.front());
q2.pop();
}
}
}
示例7: find_augmenting_path
void find_augmenting_path() {
init_bfs();
while (!Q.empty()) {
int u = Q.front(); Q.pop();
FOR (v, 1, n)
if (a[u][v] && match[u] != v && b[u] != b[v]) {
if ((v == start || match[v]) && T[match[v]])
blossom_shrink(u, v);
else if (!T[v]) {
if (!match[v]) {
T[v] = u;
finish = v;
return;
}
else {
T[v] = u;
Q.push(match[v]);
in_queue[match[v]] = true;
}
}
}
}
}
开发者ID:DArcops,项目名称:competitive-programming,代码行数:23,代码来源:10349+-+Antenna+Placement+(Lawler+-+Max+Matching+Graph).cpp
示例8: runtime_error
void
wml::CupsdDirContainer::setDirective(queue<pair<string, string> > containerId, const string& key, const string& value)
{
bool containerFound = false;
if (!containerId.empty()){
pair <string, string> temp = containerId.front();
containerId.pop();
list<CupsdDirContainer>::iterator iter;
for (iter = this->directiveContainers.begin(); iter != this->directiveContainers.end(); iter++) {
string containerIdString = temp.first + " " + temp.second;
if (iter->getId() == containerIdString) {
containerFound = true;
iter->setDirective(containerId, key, value);
}
}
if (containerFound == false) {
throw runtime_error("Container not found 4");
}
} else {
this->setDirective(key, value);
}
}
示例9: bfs
int bfs (int xk0, int yk0, int xk1, int yk1) {
if ((xk0 == xk1) && (yk0 == yk1)) return 0;
memset(vis, 0, sizeof vis);
vis[xk0][yk0] = true;
sssp[xk0][yk0] = 0;
q.push(make_pair(xk0, yk0));
pair<int, int> act;
int x, y, w, z, d;
while (!q.empty()) {
act = q.front();
q.pop();
x = act.first; y = act.second;
for (d=0; d<8; d++) {
w = x+disti[d]; z = y+distj[d];
if (check_pos(w, z) && !vis[w][z]) {
if ((w == xk1) && (z == yk1)) return sssp[x][y]+1;
vis[w][z] = true;
sssp[w][z] = sssp[x][y]+1;
q.push(make_pair(w, z));
}
}
}
}
示例10: bfs
void bfs()
{
while(!q.empty())
{
ND now=q.front();q.pop();
//cout<<now.sta<<' '<<now.x0<<' '<<now.y0<<endl;
for(int k=0;k<4;k++)
{
ND tmp;
if(!expand(now,tmp,k)) continue;
if(tmp.sta==tar)
{
printf("%d\n",tmp.step);
exit(0);
}
if(!h[tmp.sta])
{
h[tmp.sta]=1;
q.push(tmp);
}
}
}
}
示例11: string
void CReplay :: AddTimeSlot2( queue<CIncomingAction *> actions )
{
BYTEARRAY Block;
Block.push_back( REPLAY_TIMESLOT2 );
UTIL_AppendByteArray( Block, (uint16_t)0, false );
UTIL_AppendByteArray( Block, (uint16_t)0, false );
while( !actions.empty( ) )
{
CIncomingAction *Action = actions.front( );
actions.pop( );
Block.push_back( Action->GetPID( ) );
UTIL_AppendByteArray( Block, (uint16_t)Action->GetAction( )->size( ), false );
UTIL_AppendByteArrayFast( Block, *Action->GetAction( ) );
}
// assign length
BYTEARRAY LengthBytes = UTIL_CreateByteArray( (uint16_t)( Block.size( ) - 3 ), false );
Block[1] = LengthBytes[0];
Block[2] = LengthBytes[1];
m_CompiledBlocks += string( Block.begin( ), Block.end( ) );
}
示例12: main
int main(){
int t;
inp(t);
while(t--){
int n,val;
inp(n);
while(!q.empty())
q.pop();
pairs x=bfs(n);
if(x.X.X==-1)
cout<<-1<<endl;
else
{
rep(i,x.X.Y)
cout<<8;
rep(i,x.X.X)
cout<<6;
cout<<endl;
}
}
return 0;
}
示例13: solve
void solve() {
while(!q.empty()) {
int tmp = q.front();
q.pop();
if(!reported[tmp]) {
blocked[tmp] = true;
continue;
}
for(int i = 0; i < g[tmp].size(); i ++)
if(!used[ g[tmp][i] ]) {
used[ g[tmp][i] ] = true;
q.push(g[tmp][i]);
}
}
memset(used, 0, sizeof(used));
dfs(1);
cout << p - cnt << endl;
}
示例14: main
int main()
{
char s1[3],s2[3];
while(scanf("%s%s",s1,s2)==2){
sx = s1[0] - 'a', sy = s1[1] - '1';
dx = s2[0] - 'a', dy = s2[1] - '1';
while(!x.empty()){
x.pop();
y.pop();
}
memset(vis,0,sizeof(vis));
memset(len,0,sizeof(len));
x.push(sx);
y.push(sy);
if(sx==dx&&sy==dy)
printf("To get from %s to %s takes 0 knight moves.\n",s1,s2);
else{
bfs(sx,sy);
printf("To get from %s to %s takes %d knight moves.\n",s1,s2,sum);
}
}
return 0;
}
示例15: bfs
int bfs() {
int code = encode(0, SRC);
q.push({code, 0});
vis[code] = true;
while (!q.empty()) {
Item item = q.front();
q.pop();
code = item.c;
int d = item.d;
int pos, x;
decode(code, pos, x);
if (x == DST) return d;
swap0(pos, x, d);
swap1(pos, x, d);
up(pos, x, d);
down(pos, x, d);
left(pos, x, d);
right(pos, x, d);
}
assert(0);
return 0;
}