标签:script 竞赛 set end des output sub ott pac
1 #include<bits/stdc++.h> 2 using namespace std; 3 const int maxn=2020; 4 int gp[maxn][maxn]; 5 int gq[maxn][maxn]; 6 vector<int> mp[maxn]; 7 vector<int> mq[maxn]; 8 bool check_P(int x) 9 { 10 int v,u; 11 for(int i=0;i<mp[x].size();++i){ 12 v=mp[x][i]; 13 for(int j=0;j<mp[v].size();++j){ 14 u=mp[v][j]; 15 if(gp[x][u]!=1) 16 return false; 17 } 18 } 19 return true; 20 } 21 bool check_Q(int x) 22 { 23 int v,u; 24 for(int i=0;i<mq[x].size();++i){ 25 v=mq[x][i]; 26 for(int j=0;j<mq[v].size();++j){ 27 u=mq[v][j]; 28 if(gq[x][u]!=1) 29 return false; 30 } 31 } 32 return true; 33 } 34 int main() 35 { 36 ios::sync_with_stdio(false); 37 //freopen("in.txt","r",stdin); 38 int t,n; 39 char s[maxn]; 40 cin>>t; 41 while(t--) 42 { 43 memset(gp,0,sizeof(gp)); 44 memset(gq,0,sizeof(gq)); 45 cin>>n; 46 for(int i=1;i<=n;++i){ 47 mp[i].clear(); 48 mq[i].clear(); 49 } 50 for(int i=1;i<=n;++i){ 51 cin>>s+1; 52 for(int j=1;j<=n;++j){ 53 if(s[j]==‘P‘){ 54 gp[i][j]=1; 55 mp[i].push_back(j); 56 } 57 else if(s[j]==‘Q‘){ 58 gq[i][j]=1; 59 mq[i].push_back(j); 60 } 61 } 62 } 63 bool flag=true; 64 for(int i=1;i<=n;++i){ 65 if(check_P(i)==false||check_Q(i)==false){ 66 flag=false; 67 break; 68 } 69 } 70 if(flag) 71 cout<<"T"<<endl; 72 else 73 cout<<"N"<<endl; 74 } 75 return 0; 76 }
标签:script 竞赛 set end des output sub ott pac
原文地址:http://www.cnblogs.com/SCaryon/p/7374897.html