uva 11967 - Hic-Hac-Hoe

来源:互联网 发布:软件加人规则 编辑:程序博客网 时间:2024/05/22 22:44

Q  — Hic-Hac-Hoe

Time Limit: 2 sec
Memory Limit: 32 MB

Everybody knows how to play tic-tac-toe. If accidentally you do not know the rules of this game, you can always consult Wikipedia.

In this problem we will use a slightly different version of tic-tac-toe. First, the game board is not limited to 3x3 cells, but considered infinite. Also in order to win a player must get not 3 but at least knoughts or crosses in a line (horizontal, vertical or diagonal).

In modified tic-tac-to version it is not so easy to determine a winner. So in this problem you will be given a list of turns performed by the players during the game and you need to determine the winner.

INPUT

There is a number of tests T (T ≤ 100) on the first line. Each test case is described by the two numbers n k (n ≤ 105k ≤ 5), where n stands for number of turns for both players and k for winning line size. Next line contains n pairs of signed 32-bit integers x y — coordinates of each players turn. All turns have been performed sequentially by both players and crosses have always started a game.

OUTPUT

For each test case output a single line "Case T: S". Where T is the test case number (starting from 1) and Sis equal to "crosses" or "noughts" if one of them has a winning line. If nobody yet has won a game output"none" and if both players have winning lines output "error" for "S".

SAMPLE INPUT

23 20 0 1 1 1 04 20 0 -1 0 1 1 -1 1

SAMPLE OUTPUT

Case 1: crossesCase 2: error

Problem by: Aleksej Viktorchik; Leonid Sislo

Huge Easy Contest #2


水题一道,在无限大的棋盘上玩hic-hac-hoe,用map存,然后枚举每个点,最多八个方向拓展k步。

#include <cstdio>#include <algorithm>#include <vector>#include <map>#include <queue>#include <iostream>#include <stack>#include <set>#include <cstring>#include <stdlib.h>#include <cmath>using namespace std;typedef long long LL;typedef pair<int, int> P;const int maxn = 100 + 5;int n, k;map<P, int> M;vector<P> v;bool judge(int x, int y){    int kind = M[P(x, y)];    // right    int tag = 1;    for(int i = 1;i < k;i++){        int tx = x+i;        int ty = y;        if(M.count(P(tx, ty)) == 0 || M[P(tx, ty)] != kind){            tag = 0;            break;        }    }    if(tag) return true;    // left    tag = 1;    for(int i = 1;i < k;i++){        int tx = x-i;        int ty = y;        if(M.count(P(tx, ty)) == 0 || M[P(tx, ty)] != kind){            tag = 0;            break;        }    }    if(tag) return true;    //up    tag = 1;    for(int i = 1;i < k;i++){        int tx = x;        int ty = y+i;        if(M.count(P(tx, ty)) == 0 || M[P(tx, ty)] != kind){            tag = 0;            break;        }    }    if(tag) return true;    //down    tag = 1;    for(int i = 1;i < k;i++){        int tx = x;        int ty = y-i;        if(M.count(P(tx, ty)) == 0 || M[P(tx, ty)] != kind){            tag = 0;            break;        }    }    if(tag) return true;    //right up    tag = 1;    for(int i = 1;i < k;i++){        int tx = x+i;        int ty = y+i;        if(M.count(P(tx, ty)) == 0 || M[P(tx, ty)] != kind){            tag = 0;            break;        }    }    if(tag) return true;    //left up    tag = 1;    for(int i = 1;i < k;i++){        int tx = x-i;        int ty = y+i;        if(M.count(P(tx, ty)) == 0 || M[P(tx, ty)] != kind){            tag = 0;            break;        }    }    if(tag) return true;    //right down    tag = 1;    for(int i = 1;i < k;i++){        int tx = x+i;        int ty = y-i;        if(M.count(P(tx, ty)) == 0 || M[P(tx, ty)] != kind){            tag = 0;            break;        }    }    if(tag) return true;    //left down    tag = 1;    for(int i = 1;i < k;i++){        int tx = x-i;        int ty = y-i;        if(M.count(P(tx, ty)) == 0 || M[P(tx, ty)] != kind){            tag = 0;            break;        }    }    if(tag) return true;    return false;}int main(){    int t, kase = 0;    scanf("%d", &t);    while(t--){        kase++;        scanf("%d%d", &n, &k);        M.clear();        v.clear();        for(int i = 0;i < n;i++){            int x, y;            scanf("%d%d", &x, &y);            M[P(x, y)] = i%2;            v.push_back(P(x, y));        }        int tagc = 0, tagn = 0;        for(int i = 0;i < n;i++){            if(judge(v[i].first, v[i].second)){                if(i%2 == 0) tagc = 1;                else tagn = 1;            }        }        printf("Case %d: ", kase);        if(tagc == 1 && tagn == 1){            printf("error\n");        }        else if(tagc == 0 && tagn == 0){            printf("none\n");        }        else if(tagc == 1){            printf("crosses\n");        }        else{            printf("noughts\n");        }    }    return 0;}


0 0
原创粉丝点击