zoukankan      html  css  js  c++  java
  • Brexit Gym

    题目链接:Brexit

    vector的使用(vector存边),巧用queue,相当于Bfs

     1 /* */
     2 # include <iostream>
     3 # include <cstdio>
     4 # include <cstring>
     5 # include <string>
     6 # include <memory>
     7 # include <cstdlib>
     8 # include <cmath>
     9 # include <climits>
    10 # include <cctype>
    11 # include <cassert>
    12 # include <utility>
    13 # include <deque>
    14 # include <queue>
    15 # include <stack>
    16 # include <vector>
    17 # include <bitset>
    18 # include <set>
    19 # include <map>
    20 # include <functional>
    21 # include <algorithm>
    22 using namespace std;
    23  
    24 # define lson l,m,rt<<1
    25 # define rson m+1,r,rt<<1|1
    26 # define lowbit(x)(x&(-x))
    27 # define lcm(a,b)(a*b/__gcd(a,b))
    28 typedef long long ll;
    29 const ll mod=1e9+7;
    30 const int maxn=2e5+10;
    31 const double eps=1e-18;
    32 const double pi=acos(-1.0);
    33 int n, m, c, l;
    34 int de[maxn];
    35 vector<int>nex[maxn];
    36 queue<int>qu;
    37 int flag[maxn];
    38  
    39 int main()
    40 {
    41     int t;
    42     while( ~ scanf("%d%d%d%d", &n, &m, &c, &l) )
    43     {
    44         for(int i=1; i<=n; i++ )
    45         {
    46             nex[i].clear();
    47             de[i]=0;
    48             flag[i]=0;
    49         }
    50  
    51         while( !qu.empty() )
    52             qu.pop();
    53         for(int i=1; i<=m; i++ )
    54         {
    55             int u, v;
    56             scanf("%d%d", &u, &v);
    57             nex[u].push_back(v);
    58             nex[v].push_back(u);
    59             de[u]++;
    60             de[v]++;
    61         }
    62  
    63         flag[l]=1;
    64         qu.push(l);
    65         while( !qu.empty() )
    66         {
    67             int cur=qu.front();
    68             qu.pop();
    69             for(int i=0; i<nex[cur].size(); i++ )
    70             {
    71                 de[nex[cur][i]]--;
    72                 if(  de[nex[cur][i]]<=nex[nex[cur][i]].size()/2 && flag[nex[cur][i]]==0 )
    73                 {
    74                     flag[nex[cur][i]] = 1;//避免重复入栈
    75                     qu.push(nex[cur][i]);
    76                 }
    77             }
    78         }
    79         if( flag[c]==1 )
    80             cout<<"leave"<<endl;
    81         else
    82             cout<<"stay"<<endl;
    83     }
    84     return 0;
    85 }
  • 相关阅读:
    x01.Weiqi.6: 立体棋子
    x01.Game.MapEditor: 地图编辑器
    SQL Server插入中文出现乱码??的解决办法
    Cachecontrol使用:header('Cachecontrol:private')
    验证身份证号码Javascript代码
    .Net GDI+缩放绘图
    Access(JETSQL)问题集锦
    Android开发中Google谷歌地图坐标系怎么转Baidu百度地图坐标系
    21、桥接模式(Bridge模式)详解
    22、装饰模式(装饰设计模式)详解
  • 原文地址:https://www.cnblogs.com/wsy107316/p/11390676.html
Copyright © 2011-2022 走看看