Uva-1589 HDU-4121 Xiangqi(大毒瘤模拟题)

首先,给大家一些测试数据

2 1 4
G 10 5
R 6 4
3 1 5
H 4 5
G 10 5
C 7 5
4 1 4
H 3 2
G 10 5
R 3 3
R 2 1
4 1 4
G 10 5
C 9 4
C 8 4
C 2 4
4 2 5
H 2 3
R 1 1
G 10 4
H 3 8
3 1 4
G 10 4
R 9 4
R 6 5
6 3 5
R 1 1
R 2 1
H 5 2
H 4 1
C 4 3
H 1 7
4 1 4
G 10 4
R 10 5
C 6 6
C 8 4
3 1 4
G 10 5
R 8 4
R 2 4
3 1 5
G 10 5
R 10 4
R 10 6
0 0 0
测试数据

其次,是AC代码

  1 #include <bits/stdc++.h>
  2 
  3 using namespace std;
  4 
  5 typedef long long ll;
  6 
  7 int X2[] = {1,0,0,-1};
  8 int Y2[] = {0,1,-1,0};
  9 vector<char> cate(10);
 10 vector<pair<int,int>> pos(10);
 11 
 12 bool inChessBoard(int x,int y)
 13 {
 14     return x>0&&y>0&&x<=10&&y<=9;
 15 }
 16 
 17 bool inPalace(int x,int y)
 18 {
 19     return y>=4&&y<=6&&x<=3;
 20 }
 21 
 22 vector<pair<int,int>> mid(int x1,int y1,int x2,int y2)
 23 {
 24     vector<pair<int,int>> result;
 25     if(x1==x2)
 26     {
 27         if(y1>y2)
 28         {
 29             for(int k = 0;k < cate.size();k ++)
 30             {
 31                 if(pos[k].first==x1&&pos[k].second<y1&&pos[k].second>y2)
 32                     result.push_back({pos[k].first,pos[k].second});
 33             }
 34         }
 35         else if(y1<y2)
 36         {
 37             for(int k = 0;k < cate.size();k ++)
 38             {
 39                 if(pos[k].first==x1&&pos[k].second>y1&&pos[k].second<y2)
 40                     result.push_back({pos[k].first,pos[k].second});
 41             }
 42         }
 43     }
 44     else if(y1==y2)
 45     {
 46         if(x1>x2)
 47         {
 48             for(int k = 0;k < cate.size();k ++)
 49             {
 50                 if(pos[k].second==y1&&pos[k].first>x2&&pos[k].first<x1)
 51                     result.push_back({pos[k].first,pos[k].second});
 52             }
 53         }
 54         else if(x1<x2)
 55         {
 56             for(int k = 0;k < cate.size();k ++)
 57             {
 58                 if(pos[k].second==y1&&pos[k].first<x2&&pos[k].first>x1)
 59                     result.push_back({pos[k].first,pos[k].second});
 60             }
 61         }
 62     }
 63     return result;
 64 } 
 65 
 66 bool blackGSurvive(int BGx,int BGy)
 67 {
 68     int i;
 69 
 70     for(int i = 0; i < 4; i ++)
 71     {
 72         int newX = BGx+X2[i];
 73         int newY = BGy+Y2[i];
 74 
 75         if(inChessBoard(newX,newY) && inPalace(newX,newY))
 76         {
 77             int j;
 78             for(j = 0; j < cate.size(); j ++)
 79             {
 80                 if(cate[j]=='G')
 81                 {
 82                     if(pos[j].second==newY)
 83                     {
 84                         vector<pair<int,int>> tm = mid(pos[j].first,pos[j].second,newX,newY);
 85                         if(tm.size()==0)
 86                             break;
 87                     }
 88                 }
 89                 else if(cate[j]=='R')
 90                 {
 91                     if(pos[j].first==newX)
 92                     {
 93                         if(pos[j].second==newY)
 94                         {
 95                             continue;
 96                         }
 97                         vector<pair<int,int>> tm = mid(pos[j].first,pos[j].second,newX,newY);
 98                         if(tm.size()==0)
 99                             break;
100                     }
101                     else if(pos[j].second==newY)
102                     {
103                         vector<pair<int,int>> tm = mid(pos[j].first,pos[j].second,newX,newY);
104                         if(tm.size()==0)
105                             break;
106                     }
107                 }
108                 else if(cate[j]=='C')
109                 {
110                     if(pos[j].first==newX)
111                     {
112                         vector<pair<int,int>> tm = mid(pos[j].first,pos[j].second,newX,newY);
113                         if(tm.size()==1&&tm[0].second!=newY
114                         || tm.size()==2&&(tm[0].second==newY||tm[1].second==newY))
115                             break;
116                     }
117                     else if(pos[j].second==newY)
118                     {
119                         vector<pair<int,int>> tm = mid(pos[j].first,pos[j].second,newX,newY);
120                         if(tm.size()==1&&tm[0].first!=newX
121                         || tm.size()==2&&(tm[0].first==newX||tm[1].first==newX))
122                             break;
123                     }
124                 }
125                 else if(cate[j]=='H')
126                 {
127                     int shang = 1,zuo = 1,you = 1,xia = 1;
128                     for(int k = 0; k < cate.size(); k ++)
129                     {
130                         if(j!=k&&pos[k].second==pos[j].second&&pos[k].first==pos[j].first-1)
131                             shang = 0;
132                         if(j!=k&&pos[k].second==pos[j].second&&pos[k].first==pos[j].first+1)
133                             xia = 0;
134                         if(j!=k&&pos[k].second==pos[j].second-1&&pos[k].first==pos[j].first)
135                             zuo = 0;
136                         if(j!=k&&pos[k].second==pos[j].second+1&&pos[k].first==pos[j].first)
137                             you = 0;
138                     }
139                     if(shang)
140                     {
141                         if(pos[j].first-2==newX&&pos[j].second-1==newY
142                                 || pos[j].first-2==newX&&pos[j].second+1==newY)
143                             break;
144                     }
145                     if(xia)
146                     {
147                         if(pos[j].first+2==newX&&pos[j].second-1==newY
148                                 || pos[j].first+2==newX&&pos[j].second+1==newY)
149                             break;
150                     }
151                     if(zuo)
152                     {
153                         if(pos[j].first-1==newX&&pos[j].second-2==newY
154                                 || pos[j].first+1==newX&&pos[j].second-2==newY)
155                             break;
156                     }
157                     if(you)
158                     {
159                         if(pos[j].first-1==newX&&pos[j].second+2==newY
160                                 || pos[j].first+1==newX&&pos[j].second+2==newY)
161                             break;
162                     }
163                 }
164             }
165             if(j == cate.size())
166             {
167                 return true;
168             }
169         }
170     }
171     return false;
172 }
173 
174 int main()
175 {
176     int N,BGx,BGy;
177     while(cin >> N >> BGx >> BGy)
178     {
179         if(N==BGx&&N==BGy&&N==0)
180             break;
181 
182         while(N--)
183         {
184             char type;
185             int Rx,Ry;
186             cin >> type >> Rx >> Ry;
187             cate.push_back(type);
188             pos.push_back({Rx,Ry});
189         }
190         if(blackGSurvive(BGx,BGy))
191             printf("NO\n");
192         else
193             printf("YES\n");
194         cate.clear();
195         pos.clear();
196     }
197     return 0;
198 }

你想看解答?没有!我要去歇会儿!做这种毒瘤题太浪费体力。

posted @ 2018-11-15 10:06  Asurudo  阅读(280)  评论(0编辑  收藏  举报