Codeforces Educational Codeforces Round 84 (Rated for Div. 2) B、C题解

PS: The first time I played cf education field, I was not unexpectedly educated by big guys. . . I'm still too vegan, I have to train hard.

Question B: The
question was too long during the competition. I didn't understand the question after reading it for a long time. Sure enough, the English was still too bad. . .
Rough question: There are n princesses, and each princess has his or her favorite prince (maybe more than one), according to the princess number from small to large, each time we choose the prince with the smallest number for the princess, and ask us whether it is the best match now. If not, we can choose a princess to add a person to her favorite prince to make the match the best match.
Idea: We can choose a prince for the princess every time we input. If a princess does not choose a prince, we record the princess (at most one princess), and finally we traverse the prince to find the unchosen one and output The recorded princess and prince will do (provided that the match is not optimal).
Above code:

#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f
typedef long long ll;
const int MAXN=1e5+5;
int vis[MAXN];
int main()
{
    
    
    int t,n;
    scanf("%d",&t);
    while(t--)
    {
    
    
        memset(vis,0,sizeof vis);
        scanf("%d",&n);
        int p=-1;//标记公主
        int sum,x;
        for(int i=1;i<=n;i++)
        {
    
    
            int flag=0;
            scanf("%d",&sum);
            for(int j=1;j<=sum;j++)
            {
    
    
                scanf("%d",&x);
                if(vis[x]==0&&flag==0)
                {
    
    
                    vis[x]=1;
                    flag=1;
                }
            }
            if(flag==0) p=i;
        }
        if(p==-1) printf("OPTIMAL\n");
        else
        {
    
    
            printf("IMPROVE\n");
            printf("%d ",p);
            for(int i=1;i<=n;i++)
            {
    
    
                if(vis[i]==0)
                {
    
    
                    printf("%d\n",i);
                    break;
                }
            }
        }
    }
    return 0;
}

Question C: The
general meaning of the question: There is a n*m board with k chips on it. The position of each chip is (xi,yi)(1=<i<=k). I can perform four operations up, down, left, and right. To move all the chips, give the position (sxi, syi) that each chip needs to pass after moving. When the chip is on the wall and the moving direction is toward the wall, the chip keeps its current position. Ask the number of operations you need and the specific Steps.
Idea: Because the title does not require the limit of operands, you can move all the chips to the upper left corner first, and then traverse from the upper left corner to the lower right corner.
Above code:

#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f
typedef long long ll;
const int MAXN=5e4+5;
int main()
{
    
    
    int n,m,k;
    scanf("%d%d%d",&n,&m,&k);
    int x,y;//输入的数据没有用,所以不需要存储
    for(int i=1;i<=k;i++)
    {
    
    
        scanf("%d%d",&x,&y);
    }
    for(int i=1;i<=k;i++)
    {
    
    
        scanf("%d%d",&x,&y);
    }
    int flag=1;
    string ans="";
    for(int i=1;i<=m-1;i++)
    {
    
    
        ans+='L';
    }
    for(int i=1;i<=n-1;i++)
    {
    
    
        ans+='U';
    }
    for(int i=1;i<=m-1;i++)
    {
    
    
        ans+='R';
    }
    for(int i=1;i<=n-1;i++)
    {
    
    
        ans+='D';
        flag=0-flag;
        if(flag<0)
        {
    
    
            for(int j=1;j<=m-1;j++) ans+='L';
        }
        else
        {
    
    
            for(int j =1;j<=m-1;j++) ans+='R';
        }
    }
    cout<<ans.size()<<endl<<ans<<endl;
    return 0;
}

Guess you like

Origin blog.csdn.net/weixin_45755679/article/details/105069005