zoukankan      html  css  js  c++  java
  • CodeForces 786A Berzerk 博弈?BFS瞎搞

    ans[i][j]

    i号选手在位置j行动的结果。

    预处理,将每位选手能够直接到达黑洞的点

    ans[1][(n-a[1][i]+n) % n] = -1; 表示必赢的点
    把这些点加入到队列,作为BFS的起点
    对于必赢点,敌人能够到达必赢点的点标记ans[敌人][能到该点(必赢)的点]++;
    当修改后ans[选手][点]==step_num[本选手] 表示能到的点都是敌人的必赢点,那么本点必输,加入队列。
    对于必输点,敌人能够到达必输点的点是必赢点,如果没被加入到队列,那么敌人必赢点加入队列,标记为-1;

    结果输出:
    ==-1必赢
    ==step_num[本选手] 必输
    其余loop

      1 #include <cstdio>
      2 #include <cmath>
      3 #include <iostream>
      4 #include <cstring>
      5 #include <cmath>
      6 #include <queue>
      7 using namespace std;
      8 int a[3][11111];
      9 int ans[3][11111];
     10 struct dd
     11 {
     12     int id;
     13     int b;
     14 };
     15 queue <dd> Q;
     16 int main()
     17 {
     18     int n;
     19     int s[3];
     20     dd D;
     21     cin >> n;
     22     cin >> s[0];
     23 
     24     for (int i = 1; i <= s[0]; i++)
     25         scanf("%d", & a[0][i]);
     26     cin >> s[1];
     27     for (int i = 1; i <= s[1]; i++)
     28         scanf("%d", & a[1][i]);
     29 
     30     memset(ans, 0, sizeof(ans));
     31     for (int i = 1; i <= s[0]; i++)
     32     {
     33         ans[0][(n - a[0][i] + n) % n] = -1;
     34         D.b = 0;
     35         D.id = (n - a[0][i] + n) % n;
     36         Q.push(D);
     37     }
     38     for (int i = 1; i <= s[1]; i++)
     39     {
     40         ans[1][(n - a[1][i] + n) % n] = -1;
     41         D.b = 1;
     42         D.id = (n - a[1][i] + n) % n;
     43         Q.push(D);
     44     }
     45     while (!Q.empty())
     46     {
     47         D = Q.front();
     48         Q.pop();
     49         int b = D.b;
     50         int id = D.id;
     51         if (ans[b][id] == -1)
     52         {
     53             for (int i = 1; i <= s[!b] ; i++)
     54             {
     55                 int from = (id - a[!b][i] + n) % n;
     56 
     57                 if ((ans[!b][from] != -1) && ans[!b][from] != s[!b])
     58                 {
     59                     ans[!b][from]++;
     60                     if (ans[!b][from] == s[!b])
     61                     {
     62                         D.b = !b;
     63                         D.id = from;
     64                         Q.push(D);
     65                     }
     66                 }
     67 
     68             }
     69         }
     70         else
     71         {
     72             for (int i = 1; i <= s[!b] ; i++)
     73             {
     74                 int from = (id - a[!b][i] + n) % n;
     75                 if ((ans[!b][from] != -1) && ans[!b][from] != s[!b])
     76                 {
     77                     D.b = !b;
     78                     D.id = from;
     79                     ans[!b][from] = -1;
     80                     Q.push(D);
     81                 }
     82             }
     83         }
     84     }
     85     for (int i = 1; i < n - 1; i++)
     86         if (ans[0][i] == -1) cout << "Win" << " ";
     87         else if (ans[0][i] == s[0]) cout << "Lose" << " ";
     88         else cout << "Loop" << " ";
     89     if (ans[0][n - 1] == -1) cout << "Win" << endl;
     90     else if (ans[0][n - 1] == s[0]) cout << "Lose" << endl;
     91     else cout << "Loop" << endl;
     92     for (int i = 1; i < n - 1; i++)
     93         if (ans[1][i] == -1) cout << "Win" << " ";
     94         else if (ans[1][i] == s[1]) cout << "Lose" << " ";
     95         else cout << "Loop" << " ";
     96     if (ans[1][n - 1] == -1) cout << "Win" << endl;
     97     else if (ans[1][n - 1] == s[1]) cout << "Lose" << endl;
     98     else cout << "Loop" << endl;
     99 
    100 }
  • 相关阅读:
    《面试系列一》一个怂到极点的开始
    NuGet 私房服务使用帮助
    Nuspec 范本文件
    送给前线码农的话 – 大牛们的经典语录
    Visual Studio 增加源码头注释
    为 Orchard 增加 MVC 的脚手架.
    为 Orchard 增加扩展的存储位置
    Orchard 瘦身优化
    Hybrid Multiple Attention Network for Semantic Segmentation in Aerial Images
    【nvidia jetson xavier】 Linux系统安装+Deepstream 5.1环境部署
  • 原文地址:https://www.cnblogs.com/HITLJR/p/6613061.html
Copyright © 2011-2022 走看看