Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int dir[9][2]={{0,1},{1,0},{-1,0},{0,1},{0,-1},{-1,-1},{-1,1},{1,-1}};
- struct node{
- int x,y,cnt = 0;
- }beg;
- enum
- {
- EMPTY, //0
- BLACK, //1
- WHITE //2
- };
- #define ROWS 19
- #define COLS ROWS
- char chess[ROWS][COLS];
- char mp[ROWS][COLS];
- int vis[ROWS][COLS];
- enum
- {
- BLACK_WIN, //0
- WHITE_WIN, //1
- GO_ON //2
- };
- int dfs(int role)
- {
- int len=0;
- for(int y=1;y<=ROWS;y++)
- {
- for(int x=1;x<=COLS;x++)
- {
- if(chess[y][x]==role)
- {
- for(int k=0;k<8;k++)
- {
- int ny=y;
- int nx=x;
- int h;
- for(h=0;h<5;h++)
- {
- if(chess[ny][nx]!=role)
- break;
- nx+=dir[k][1];
- ny+=dir[k][0];
- }
- len=max(h,len);
- }
- }
- }
- }
- return len;
- }
- int dfs_changlian(int x,int y,int role){
- int len=0,flag = 1;;
- for(int k=0;k<8;k++)
- {
- int ny=y;
- int nx=x;
- int h;
- int cnt = 1,cntmax = 1;
- while(1)
- {
- if(chess[ny][nx]!=role){
- if(chess[ny+dir[k][0]][nx+dir[k][1]] != role){
- break;
- }
- }
-
- nx+=dir[k][1];
- ny+=dir[k][0];
- cnt++;
- }
- cntmax = max(cnt ,cntmax);
- if(cntmax >= 6)return 1;
- }
- return 0;
-
- }
- int ban44(int x,int y){
-
- }
- int ban33(int x,int y){
- //33
- int num3 = 0;
- int cnt = 1;
- int cnt1 = 0;
- int pe=0;
- for(int i = 1;i <= 4;i ++){
- int tx = x-i;
- if(tx < 0 || tx > 19)continue;
- if(chess[tx][y] == 1) cnt++;
- else if(chess[tx][y] == 2) break;
- else {
- if(pe!=1){
- pe++;
- }
- else{
- pe++;
- break;
- }
- }
- }
- if(pe)cnt1++;
- pe=0;
- for(int i = 1;i <= 4; i++){
- int tx=x+i;
- if(tx > 19 || tx < 0)continue;
- if(chess[tx][y]==1) cnt++;
- else if(chess[tx][y]==2)break;
- else {
- if(pe!=1){
- pe++;
- }
- else {
- pe++;
- break;
- }
- }
- }
- if(pe)cnt1++;
- if(cnt >= 3 && cnt1 == 2)num3++;
- cnt=1;cnt1=0;pe=0;
- for(int i=1;i<=4;i++){
- int tx=x-i;
- int ty=y-i;
- if(tx > 19|| tx < 0||ty < 0||ty > 19)continue;
- if(chess[tx][ty]==1)cnt++;
- else if(chess[tx][ty]==2)break;
- else {
- if(pe!=1){
- pe++;
- }
- else {
- pe++;
- break;
- }
- }
- }
- if(pe)cnt1++;
- pe=0;
- for(int i=1;i<=4;i++){
- int tx=x+i;
- int ty=y+i;
- if(tx > 19|| tx < 0||ty < 0||ty > 19)continue;
- if(chess[tx][ty]==1) cnt++;
- else if(chess[tx][ty]==2) break;
- else {
- if(pe!=1)pe++;
- else {
- pe++;
- break;
- }
- }
- }
- if(pe)cnt1++;
- pe=0;
- if(cnt >= 3&& cnt1==2) num3++;
- cnt=1;cnt1=0;
- for(int i=1;i<=4;i++){
- int tx=x-i;
- int ty=y+i;
- if(tx > 19|| tx < 0||ty < 0||ty > 19)continue;
- if(chess[tx][ty]==1) cnt++;
- else if(chess[tx][ty]==2) break;
- else {
- if(pe!=1)pe++;
- else {
- pe++;
- break;
- }
- }
- }
- if(pe)cnt1++;
- pe=0;
- for(int i=1;i<=4;i++){
- int tx=x+i;
- int ty=y-i;
- if(tx > 19|| tx < 0||ty < 0||ty > 19)continue;
- if(chess[tx][ty]==1) cnt++;
- else if(chess[tx][ty]==2) break;
- else {
- if(pe!=1){
- pe++;
- }
- else {
- pe++;
- break;
- }
- }
- }
- if(pe)cnt1++;
- pe=0;
- if(cnt>=3&&cnt1==2)num3++;
- cnt1=0;cnt=1;
- for(int i=1;i<=4;i++){
- int ty=y-i;
- if(ty> 19|| ty < 0)continue;
- if(chess[x][ty]==1) cnt++;
- else if(chess[x][ty]==2) break;
- else {
- if(pe!=1){
- pe++;
- }
- else {
- pe++;
- break;
- }
- }
- }
- if(pe)cnt1++;
- pe=0;
- for(int i=1;i<=4;i++){
- int ty=y-i;
- if(ty> 19|| ty < 0)continue;
- if(chess[x][ty]==1) cnt++;
- else if(chess[x][ty]==2) break;
- else {
- if(pe!=1){
- pe++;
- }
- else {
- pe++;
- break;
- }
- }
- }
- if(pe)cnt1++;
- pe=0;
- if(cnt>=3&&cnt1==2)num3++;
- if(num3>=1){
- return 1;
- }
- else return 0;
- }
- int putChess(int role, int row, int col)
- {
- chess[row][col] = role;
- int flag1 = dfs(role);
- if(flag1 >= 5){
- if(role == 2)return WHITE_WIN;
- else return BLACK_WIN;
- }
- else{
- if(role == 1){
- int flag2 = ban33(row,col);
- int flag3 = ban44(row,col);
- int flag4 = dfs_changlian(row,col,role);
-
- if(!flag2&&!flag3&&!flag4){
- return GO_ON;
- }
- else return WHITE_WIN;
-
- }
- }
- return GO_ON;
- }
- int main()
- {
- freopen(”15.txt“,”r“,stdin);
- freopen(”out.txt“,”w“,stdout);
- char line[20];
- char *str = NULL;
- int ret = GO_ON;
- do {
- str = fgets(line, 20, stdin);
- if(str == NULL)break;
-
- int role, row, col;
- sscanf(line, ”%d %d %d“, &role, &row, &col);
- ret = putChess(role, row-1, col-1);
- } while(ret == GO_ON);
- if(ret == BLACK_WIN)
- printf(”black win“);
- else if(ret == WHITE_WIN)
- printf(”white win“);
- else
- printf(”not end“);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement