zoukankan      html  css  js  c++  java
  • HDU 5961 传递

    题目链接:HDU-5961

    用vector存直接暴力dfs也可AC。正解如下(看了icpc-camp的题解,感觉写的很好,直接引用了。原链接:2016 合肥解题报告):

     代码(暴力)如下:

     1 #include"cstdio"
     2 #include"iostream"
     3 #include"cstring"
     4 #include"algorithm"
     5 #include"cstdlib"
     6 #include"vector"
     7 using namespace std;
     8 typedef long long LL;
     9 const int MAXN=3000;
    10 
    11 char s[MAXN][MAXN];
    12 vector<int> nextP[MAXN],nextQ[MAXN];
    13 int main()
    14 {
    15 #ifdef LOCAL
    16     freopen("in.txt","r",stdin);
    17     //freopen("out.txt","w",stdout);
    18 #endif
    19     int t;
    20     scanf("%d",&t);
    21     for(int tt=1;tt<=t;tt++)
    22     {
    23         int n;
    24         scanf("%d",&n);
    25         for(int i=1;i<=n;i++)
    26         {
    27             nextP[i].clear();
    28             nextQ[i].clear();
    29         }
    30         for(int i=1;i<=n;i++)
    31         {
    32             if(getchar()=='
    ') getchar();
    33             for(int j=1;j<=n;j++)
    34             {
    35                 s[i][j]=getchar();
    36                 if(s[i][j]=='P')
    37                     nextP[i].push_back(j);
    38                 else if(s[i][j]=='Q')
    39                     nextQ[i].push_back(j);
    40             }
    41         }
    42         bool ok=true;
    43         for(int i=1;i<=n;i++)
    44         {
    45             for(unsigned int j=0;ok && j<nextP[i].size();j++)
    46             {
    47                 int u=nextP[i][j];
    48                 for(unsigned int k=0;ok && k<nextP[u].size();k++)
    49                 {
    50                     int v=nextP[u][k];
    51                     if(s[i][v]!='P')
    52                         ok=false;
    53                 }
    54             }
    55         }
    56         for(int i=1;i<=n;i++)
    57         {
    58             for(unsigned int j=0;ok && j<nextQ[i].size();j++)
    59             {
    60                 int u=nextQ[i][j];
    61                 for(unsigned int k=0;ok && k<nextQ[u].size();k++)
    62                 {
    63                     int v=nextQ[u][k];
    64                     if(s[i][v]!='Q')
    65                         ok=false;
    66                 }
    67             }
    68         }
    69         if(ok) printf("T
    ");
    70         else printf("N
    ");
    71     }
    72     return 0;
    73 }
  • 相关阅读:
    go——数组
    go——流程控制
    go——基本类型
    go——基本构成要素
    go——常量
    go——变量
    go——标准命令
    go——工程结构
    python 优雅的使用正则表达式 ~ 1
    python 安装操作 MySQL 数据库.
  • 原文地址:https://www.cnblogs.com/zarth/p/6671252.html
Copyright © 2011-2022 走看看