深夜切题——ly与lyon的终极巅峰对决

ly与lyon的终极巅峰对决

时间限制:1000MS  内存限制:65535K

Description

    从前有一天,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


一看题,凭我的水平就暴力扫吧。。。打完机脑子里没有其他方法(蠢。。。)(run)

//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <cstring>
#include <cmath>
//#include <cctype>
#include <queue>
#include <vector>
#include <string>
#include <stack>
#include <set>
#include <map>
//#include <sstream>
#include <iostream>
#include <bitset>
#include <algorithm>
using namespace std;

#define MP make_pair
#define PB push_back
#define mst(a,b) memset((a),(b),sizeof(a))
#define TEST cout<<"*************************"<<endl

#define rep(s,n,up) for(int i = (s); i < (n); i+=(up))
#define per(n,e,down) for(int i = (n); i >= (e); i-=(down))
#define rep1(s,n,up) for(int j = (s); j < (n); j+=(up))
#define per1(n,e,down) for(int j = (n); j >= (e); j-=(down))

typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int, int> Pii;
typedef vector<int> Vi;
typedef vector<Pii> Vii;
const int inf = 0x3f3f3f3f;
const LL INF = (1uLL << 63) - 1;
const double Pi = acos(-1.0);
const int maxn = (1 << 16) + 7;
const uLL Hashmod = 29050993;
const double esp=1e-6;


#define local
int chessboard[1001][1001],n,m,flag=0;

void checkrow(int i,int j,int step)
{
    int c=0,mark;
    if(step%2)mark=1;else mark=2;
    int y=j;
    while(y-1>=0&&chessboard[i][--y]==mark)++c;
    y=j;
    while(y+1<=n&&chessboard[i][++y]==mark)++c;
    if(c>=4)flag=1;
}
void checkcolumn(int i,int j,int step)
{
    int c=0,mark;
    if(step%2)mark=1;else mark=2;
    int x=i;
    while(x-1>=0&&chessboard[--x][j]==mark)++c;
    x=i;
    while(x+1<=n&&chessboard[++x][j]==mark)++c;
    if(c>=4)flag=1;
}
void checkxright(int i,int j,int step)
{
    int c=0,mark;
    if(step%2)mark=1;else mark=2;
    int x=i,y=j;
    while(x-1>=0&&y-1>=0&&chessboard[--x][--y]==mark)++c;
    x=i,y=j;
    while(x+1<=n&&y+1<=n&&chessboard[++x][++y]==mark)++c;
    if(c>=4)flag=1;
}
void checkxleft(int i,int j,int step)
{
    int c=0,mark;
    if(step%2)mark=1;else mark=2;
    int x=i,y=j;
    while(x-1>=0&&y+1<=n&&chessboard[--x][++y]==mark)++c;
    x=i,y=j;
    while(x+1<=n&&y-1>=0&&chessboard[++x][--y]==mark)++c;
    if(c>=4)flag=1;
}
int main() {
#ifdef local
    freopen("input.txt", "r", stdin);
    //freopen("output.txt","w",stdout);
#endif
    //ios::sync_with_stdio(0);
    //cin.tie();
    mst(chessboard,0);
    int i,j,k;
    scanf("%d%d",&n,&m);
    int step=0;
    while(step++<m){
        scanf("%d%d",&i,&j);
        if(!flag){
            if(step%2)chessboard[i][j]=1;
            else chessboard[i][j]=2;
            if(!flag)
                {checkrow(i,j,step);k=step;}
            if(!flag)
                {checkcolumn(i,j,step);k=step;}
            if(!flag)
                {checkxright(i,j,step);k=step;}
            if(!flag)
                {checkxleft(i,j,step);k=step;}
        }
    }
    /*rep(0,n+1,1)
    {rep1(0,n+1,1)
    printf("%d ",chessboard[i][j]);
    printf("\n");}*/
    if(flag)printf("%d\n",k);
    else printf("baga\n");
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值