UVa 1589 (implement)

思维失误了,是红子可以被吃掉,但被另外一个红字管辖就不能被吃。

/*
* 20171108
*/

//#define LOCAL 
//#define TEST

#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int dx[] = {1,-1,-2,-2,-1,1,2,2};
const int dy[] = {-2,-2,-1,1,2,2,1,-1};
const int fx[] = {0,-1,0,1};
const int fy[] = {-1,0,1,0};
char mp[20][20];
int ans[20][20];
int a,b;

int main()
{
    #ifdef LOCAL
        freopen("input.txt","r",stdin);
        freopen("ans.txt","w",stdout);
    #endif
    int n;
    while(scanf("%d%d%d",&n,&a,&b)==3&&n)
    {
        memset(mp,0,sizeof(mp));
        memset(ans,0,sizeof(ans));
        for(int i=1;i<=10;i++) for(int j=1;j<=9;j++) ans[i][j] = 1;

        while(n--)
        {
            char tc[5];
            int x,y;
            scanf("%s%d%d",tc,&x,&y);
            mp[x][y] = tc[0];
        }

        //solve
        for(int i=1;i<=10;i++)
        {
            for(int j=1;j<=9;j++)
            {
                if(mp[i][j]=='R'||mp[i][j]=='G')
                {
                    for(int k=j+1;k<=9;k++)
                    {
                        ans[i][k] = 0;
                        if(mp[i][k]!=0) break;
                    }
                    for(int k=j-1;k>=1;k--)
                    {
                        ans[i][k] = 0;
                        if(mp[i][k]!=0) break;
                    }
                    for(int k=i+1;k<=10;k++)
                    {
                        ans[k][j] = 0;
                        if(mp[k][j]!=0) break;
                    }
                    for(int k=i-1;k>=1;k--)
                    {
                        ans[k][j] = 0;
                        if(mp[k][j]!=0) break;
                    }
                    #ifdef TEST
                        printf("%c\n",mp[i][j]);
                        for(int i=0;i<11;i++)
                        {
                            for(int j=0;j<10;j++)
                            {
                                printf("%d ",ans[i][j]);
                            }
                            printf("\n");
                        }
                    #endif
                }else if(mp[i][j]=='H')
                {
                    for(int k=0;k<4;k++)
                    {
                        if(mp[i+fx[k]][j+fy[k]]==0)
                        {
                            if(i+dx[k*2]>=0&&j+dy[k*2]>=0) ans[i+dx[k*2]][j+dy[k*2]] = 0;
                            if(i+dx[k*2+1]>=0&&j+dy[k*2+1]>=0) ans[i+dx[k*2+1]][j+dy[k*2+1]] = 0;
                        }
                    }
                    #ifdef TEST
                        printf("%c\n",mp[i][j]);
                        for(int i=0;i<11;i++)
                        {
                            for(int j=0;j<10;j++)
                            {
                                printf("%d ",ans[i][j]);
                            }
                            printf("\n");
                        }
                    #endif
                }else if(mp[i][j]=='C')
                {
                    bool flag = true;
                    for(int k=j+1;k<=9&&flag;k++)
                    {
                        if(mp[i][k]!=0)
                        {
                            for(int u=k+1;u<=9;u++)
                            {
                                ans[i][u] = 0;
                                if(mp[i][u]!=0){flag = false; break;}
                            }
                        }
                    }
                    flag = true;
                    for(int k=j-1;k>=1&&flag;k--)
                    {
                        if(mp[i][k]!=0)
                        {
                            for(int u=k-1;u>=1;u--)
                            {
                                ans[i][u] = 0;
                                if(mp[i][u]!=0){flag = false;break;}
                            }
                        }
                    }
                    flag = true;
                    for(int k=i+1;k<=10&&flag;k++)
                    {
                        if(mp[k][j]!=0)
                        {
                            for(int u=k+1;u<=10;u++)
                            {
                                ans[u][j] = 0;
                                if(mp[u][j]!=0){flag = false;break;}
                            }
                        }
                    }
                    flag = true;
                    for(int k=i-1;k>=1&&flag;k--)
                    {
                        if(mp[k][j]!=0)
                        {
                            for(int u=k-1;u>=1;u--)
                            {
                                ans[u][j] = 0;
                                if(mp[u][j]!=0){flag = false;break;}
                            }
                        }
                    }
                    #ifdef TEST
                        printf("%c\n",mp[i][j]);
                        for(int i=0;i<11;i++)
                        {
                            for(int j=0;j<10;j++)
                            {
                                printf("%d ",ans[i][j]);
                            }
                            printf("\n");
                        }
                    #endif
                }
            }
        }
        bool res = true;
        for(int i=0;i<4;i++) 
        {
            int ta = a+fx[i];
            int tb = b+fy[i];
            if(ta>=1&&ta<=3&&tb>=4&&tb<=6&&ans[a+fx[i]][b+fy[i]]==1){res = false;break;}
        }
        printf("%s\n",res?"YES":"NO");
    }
    return 0;
}

测试数据生成

/*
* 20171108
*/

#include <cstdio>
#include <ctime>
#include <cstdlib>
#include <cstring>

using namespace std;

int color[11][10];

void A(int a,int b,int c,int d)
{
    int x = rand()%a+b;
    int y = rand()%c+d;
    if(color[x][y]==0)
    {
        color[x][y] = 1;
        printf("%d %d\n",x,y);
    }else A(a,b,c,d);
}

int main()
{
    freopen("input.txt","w",stdout);
    int n = 1000;
    srand(time(NULL));
    while(n--)
    {
        memset(color,0,sizeof(color));
        printf("7 ");
        A(3,1,3,4);
        printf("G ");
        A(3,8,3,4);
        printf("R ");
        A(10,1,9,1);
        printf("R ");
        A(10,1,9,1);
        printf("H ");
        A(10,1,9,1);
        printf("H ");
        A(10,1,9,1);
        printf("C ");
        A(10,1,9,1);
        printf("C ");
        A(10,1,9,1);
        printf("\n");
    }
    printf("0 0 0\n");
    return 0;
}
### Implementor Implementation Usage and Issues In programming, an **implementor** typically refers to a class or structure responsible for providing concrete implementations of interfaces or abstract classes. This concept is widely used across various languages such as Java, C#, Python, and Go. Below is a detailed explanation regarding implementors' usage and potential issues. #### Understanding Interfaces and Implementations An interface defines a contract that specifies what methods must be implemented by any struct or class adhering to it. In Go, this relationship is implicit rather than explicit—any type satisfying all the methods defined in an interface automatically implements it without requiring additional declarations[^1]. For example: ```go type Sorter interface { Len() int Less(i, j int) bool Swap(i, j int) } func main() { var sorter Sorter = &CustomSort{} } ``` Here, `CustomSort` implicitly satisfies the `Sorter` interface if it provides definitions for `Len`, `Less`, and `Swap`. #### Common Challenges with Implementors Several challenges can arise when working with implementors: - **Type Safety**: Ensuring types conform strictly to their expected behavior during runtime may lead to subtle bugs unless carefully managed. - **Concurrency Handling**: If multiple goroutines interact through shared resources via calls made on these implementors, synchronization mechanisms like mutexes might become necessary. For instance, consider invoking sorting operations asynchronously using goroutines: ```go package main import ( "fmt" "sort" ) func asyncSort(slice []int) chan string { ch := make(chan string) go func() { sort.Ints(slice) defer close(ch) ch <- fmt.Sprintf("Sorted slice: %v", slice) }() return ch } func main() { slice := []int{3, 2, 5, 1, 4} resultChan := asyncSort(slice) if result := <-resultChan; len(result) > 0 { fmt.Println(result) } } ``` This demonstrates how you could leverage goroutines alongside implementors while managing concurrency effectively. #### Messaging Systems Integration When integrating messaging systems into applications utilizing implementors, one should account for reliable delivery guarantees provided by message brokers mentioned earlier[^2]: Message brokers facilitate communication between different parts of distributed systems efficiently. They allow decoupling producers from consumers enabling flexible scaling options along with fault tolerance features which enhance overall system robustness significantly. By combining both concepts — proper handling within your codebase concerning implementors plus leveraging external services offered by message queues—you achieve more resilient architectures capable of addressing complex real-world scenarios gracefully.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值