zoukankan      html  css  js  c++  java
  • Code Forces 786A Berzerk(有向图博弈)

      1 #include <iostream>
      2 #include <queue>
      3 #include <stack>
      4 #include <cstdio>
      5 #include <vector>
      6 #include <map>
      7 #include <set>
      8 #include <bitset>
      9 #include <algorithm>
     10 #include <cmath>
     11 #include <cstring>
     12 #include <cstdlib>
     13 #include <string>
     14 #include <sstream>
     15 #include <time.h>
     16 #define x first
     17 #define y second
     18 #define pb push_back
     19 #define mp make_pair
     20 #define lson l,m,rt*2
     21 #define rson m+1,r,rt*2+1
     22 #define mt(A,B) memset(A,B,sizeof(A))
     23 using namespace std;
     24 typedef long long LL;
     25 //const double PI = acos(-1);
     26 const int N=7e3+10;
     27 const LL mod=1e9+7;
     28 const int inf = 0x3f3f3f3f;
     29 const LL INF=0x3f3f3f3f3f3f3f3fLL;
     30 int step[N][2];
     31 int vis[N][2];
     32 int du[N][2];
     33 int k[2];
     34 int n;
     35 struct node
     36 {
     37     int x,y;
     38     int type;
     39 };
     40 queue<struct node> Q;
     41 void bfs()
     42 {
     43     struct node p,q;
     44     while(!Q.empty())
     45     {
     46         p=Q.front();
     47         Q.pop();
     48         if(!p.type)
     49         {
     50             int turn=!p.y;
     51             for(int i=0;i<k[turn];i++)
     52             {
     53                 int bu=(p.x+n-step[i][turn])%n;
     54                 //cout<<p.x<<" "<<bu<<endl;
     55                 if(vis[bu][turn]==-1)
     56                 {
     57                     vis[bu][turn]=1;
     58                     Q.push({bu,turn,1});
     59                 }
     60             }
     61         }
     62         else
     63         {
     64             int turn=!p.y;
     65             for(int i=0;i<k[turn];i++)
     66             {
     67                 int bu=(p.x+n-step[i][turn])%n;
     68                 du[bu][turn]--;
     69                 if(du[bu][turn]<=0&&vis[bu][turn]==-1)
     70                 {
     71                     vis[bu][turn]=0;
     72                     Q.push({bu,turn,0});
     73                 }
     74             }
     75         }
     76     }
     77 }
     78 int main()
     79 {
     80 #ifdef Local
     81     freopen("data.txt","r",stdin);
     82 #endif
     83     ios::sync_with_stdio(false);
     84     cin.tie(0);
     85     mt(vis,-1);
     86     cin>>n;
     87     cin>>k[0];
     88     for(int i=0;i<k[0];i++)cin>>step[i][0];
     89     for(int i=0;i<n;i++)du[i][0]=k[0];
     90     cin>>k[1];
     91     for(int i=0;i<k[1];i++)cin>>step[i][1];
     92     for(int i=0;i<n;i++)du[i][1]=k[1];
     93     vis[0][1]=vis[0][1]=0;//失败
     94     Q.push({0,0,0});
     95     Q.push({0,1,0});
     96     bfs();
     97     for(int d=0;d<2;d++)
     98     {
     99         for(int i=1;i<n;i++)
    100         {
    101             if(vis[i][d]==0)cout<<"Lose ";
    102             else if(vis[i][d]==1)cout<<"Win ";
    103             else cout<<"Loop ";
    104         }
    105         cout<<endl;
    106     }
    107 
    108 #ifdef Local
    109     cerr << "time: " << (LL) clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    110 #endif
    111 }
    View Code
  • 相关阅读:
    Docker安装nexus
    docker常用操作备忘
    react-01
    SBT实操指南
    Play中JSON序列化
    SPARK安装一:Windows下VirtualBox安装CentOS
    SPARK安装三:SPARK集群部署
    SPARK安装二:HADOOP集群部署
    SLICK基础
    函数式编程
  • 原文地址:https://www.cnblogs.com/27sx/p/6653114.html
Copyright © 2011-2022 走看看