SCAU 12新生赛 C ly与lyon的终极巅峰对决

C  ly与lyon的终极巅峰对决

Time Limit:1000MS  Memory Limit:65535K

题型: 编程题   语言: 无限制

 

描述

    从前有一天,ly与lyon在讨论人工智能里面的博弈问题,恰好,他们提到了五子棋。
当然,这里说的五子棋是指无禁手(不知道什么是禁手的也不用管了,跟这题没关系)的五子棋:
    黑先下,黑白轮流下,最先在横竖斜任一方向上形成连续的5个子(或以上)就算赢。

    对此,ly和lyon都有自己的一套判断局势的算法,并且根据自己的想法各写了一个判断局况的程序。然而,他们都觉得自己的程序要比对方的优秀,所以,
他们稍作改良,做成了自动决策的对局程序,并拿出来互相pk。目前需要一个自动判断胜负的程序,即最先出现5连子的判胜。

 

输入格式

    第1行输入两个数n和m,用空格分开,n为棋盘横纵坐标的最大值,m为步数:
1<=n<=1000,0<m<=n*n
    第2行到第m+1行为第一步到第m步的坐标,每行两个数,用空格分开:
x和y,1<=x,y<=n
    输入保证不存在重复下子。

(出题人LRC)

 

输出格式

    输出首次分出胜负那一步的序号(第一步为1),如果走完了都没有分出胜负,输出“baga”。

 

输入样例

5 11
3 3
2 3
2 4
4 3
4 2
3 4
1 5
3 2
5 1
1 1
1 2

 

输出样例

9

 

Provider

scau_acm

#include<stdio.h>
#include<string.h>
int bsitu[1002][1002], wsitu[1002][1002];
int operat(int n, int (*temp)[1002])
{
    int i, j, start, end, count;
    for(i=0; i<n; ++i)
    for(j=0; j<n; ++j)
    if(temp[i][j] == 1)
    {
        if(j+1-5>=0)
        {
            for(start=j, count=0; count<5 && temp[i][start]; --start, count++);
            if(count == 5)    return 1;
        }
        if(n-j-5>=0)
        {
            for(start=j, count=0; count<5 && temp[i][start]; ++start, ++count);
            if(count == 5) return 1;
        }
        if(i+1-5>=0)
        {
            for(start=i, count=0; count<5 && temp[start][j]; --start, count++);
            if(count == 5) return 1;
        }
        if(n-i-5>=0)
        {
            for(start=i, count=0; count<5 && temp[start][j]; ++start, count++);
            if(count == 5) return 1;
        }
        if(n-j-5>=0 && n-i-5>=0)
        {
            for(start=i,end=j,count=0; count<5 && temp[start][end]; ++start, ++end, ++count);
            if(count == 5) return 1;
        }
        if(n-j-5>=0 && i+1-5>=0)
        {
            for(start=i, end=j,count=0; count<5 && temp[start][end]; --start, ++end, ++count);
            if(count == 5) return 1; 
        }
        if(j+1-5>=0 && n-i-5>=0)
        {
            for(start=i, end=j, count=0; count<5 && temp[start][end]; ++start, --end, ++count);
            if(count == 5) return 1;
        }
        if(j+1-5>=0 && i+1-5>=0)
        {
            for(start=i, end=j,count=0; count<5 && temp[start][end]; --start, --end, ++count);
            if(count == 5) return 1; 
        }
    }
    return 0;
}


int main()
{
    int n, m, i, j, flag, x, y;
    scanf("%d%d", &n, &m);
    for(i=0; i<n; ++i)
    {
        memset(bsitu[i], 0, sizeof(int)*1002);
        memset(wsitu[i], 0, sizeof(int)*1002);
    }
    flag = 0;
    for(i=1; i<=m; ++i)
    {
        scanf("%d%d", &x, &y);
        if(i%2) {bsitu[x-1][y-1] = 1; if(operat(n, bsitu) && !flag) flag = i;}
        else {wsitu[x-1][y-1] = 1; if(operat(n, wsitu) && !flag) flag = i;}
    }
    if(flag) printf("%d\n", flag);
    else printf("baga\n");
    
    return 0;
}

解题思路:

这样的做法是水了点,不敢保证哪天不删掉

原文地址:https://www.cnblogs.com/liaoguifa/p/2833198.html