poj4012

简单题

判断的情况稍微有点复杂,注意判断整行都是“.”的情况

View Code
#include <iostream>

#include <cstdlib>

#include <cstdio>

#include <cstring>

#include <algorithm>

using namespace std;



#define maxn 5005



int n, m, s, k;

char st[maxn];



int cal(int a)

{

    if (a < 0)

        return 0;

    return a;

}



int main()

{

    scanf("%d%d%d%d", &m, &n, &s, &k);

    scanf("%s", st);

    int pos = find(st, st + n, '*') - st;

    if (pos == n)

    {

        if (k < s + 1 && m - k < s)

        {

            printf("Impossible\n");

            return 0;

        }

        if (n > s || cal(k - s) + cal(m - k - s + 1) > 1)

        {

            printf("Ambiguous\n");

            return 0;

        }

        printf("Unique\n");

        return 0;

    }

    if (pos + s > n)

    {

        printf("Impossible\n");

        return 0;

    }

    int pos1 = find(st + pos, st + pos + s, '.') - (st + pos);

    if (pos1 != s)

    {

        printf("Impossible\n");

        return 0;

    }

    int pos2 = find(st + pos + s, st + n, '*') - st;

    if (pos2 != n)

    {

        printf("Impossible\n");

        return 0;

    }

    if (k == 1 || k == m || s == 1 || s == m)

    {

        printf("Unique\n");

        return 0;

    }

    printf("Ambiguous\n");

    return 0;

}

你可能感兴趣的:(poj)