当前位置:网站首页>Codeforces round 712 (Div. 2) d. 3-coloring (construction)

Codeforces round 712 (Div. 2) d. 3-coloring (construction)

2022-07-05 05:27:00 solemntee

We know that if the diagonal grid is completely painted with one color , The rest can be painted casually .( Imagine if the slashes cross and fill 1, Then the position of the gap should not be written 2 Or write 3, Women can't stop us )
 Insert picture description here

So we use 1 Paint the main diagonal grid , use 2 De paint sub diagonal grid . There must be one filled first . Then paint casually !

The diagonal line is the main diagonal grid  Insert picture description here
ac Code

    #include<bits/stdc++.h>
    using namespace std;
    char a[300005];
    struct edge
    {
    
        int x,y;
    };
    queue<edge>q1,q2;
    int main()
    {
    
        int n;
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
        {
    
            if((i+j)%2==0)q1.push({
    i,j});
            else q2.push({
    i,j});
        }
        for(int i=1;i<=n*n;i++)
        {
    
            int t;
            scanf("%d",&t);
            /// If t yes 1, We will use 2 Desmear q2( Store the sub diagonal grid )
            /// If the sub diagonal grid is full , Just paint casually in the main diagonal grid 
            if(t==1)
            {
    
                if(!q2.empty())
                {
    
                    edge p=q2.front();
                    q2.pop();
                    printf("2 %d %d\n",p.x,p.y);
                }
                else
                {
    
                    edge p=q1.front();
                    q1.pop();
                    printf("3 %d %d\n",p.x,p.y);
                }
            }
            else if(t==2)
            {
    
                if(!q1.empty())
                {
    
                    edge p=q1.front();
                    q1.pop();
                    printf("1 %d %d\n",p.x,p.y);
                }
                else
                {
    
                    edge p=q2.front();
                    q2.pop();
                    printf("3 %d %d\n",p.x,p.y);
                }
            }
            else if(t==3)
            {
    
                if(!q1.empty())
                {
    
                    edge p=q1.front();
                    q1.pop();
                    printf("1 %d %d\n",p.x,p.y);
                }
                else
                {
    
                    edge p=q2.front();
                    q2.pop();
                    printf("2 %d %d\n",p.x,p.y);
                }
            }
            fflush(stdout);
        }
    }
原网站

版权声明
本文为[solemntee]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140621453371.html