2021牛客暑期多校训练营第二场

C题

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <stack>
#include  <queue>
#include  <map>
#include  <vector>
#define ll long long
using namespace std;
int n,m;
int main()
{
    cin>>n>>m;
    int sum=n*m-1;
    if(sum%2==0)
    {
         printf("NO");
    }
    else
    {
         printf("YES");
    }
    return 0;
}

I题
【题解】 广度搜索,判断重复用f[][][][]

#include<stdio.h>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream>
using namespace std;
char Map[100][100]; bool f[100][100][100][100]={false};
int ldx[4]= {0,0,-1,1},ldy[4]= {-1,1,0,0},rdx[4]= {0,0,-1,1},rdy[4]= {1,-1,0,0},h,t;
struct data
{
    int xl,yl,xr,yr;
    int sum,head,step;
} a[1000005];
void print(int tt)
{
    cout<<a[tt].sum<<endl;
    int n=0; char ans[1000005];
    while (tt!=1)
    {
        n++;
        Map[a[tt].xl][a[tt].yl]='A';
        Map[a[tt].xr][a[tt].yr]='A';
        switch (a[tt].step)
        {
        case 0:
            ans[n]='L';
            break;
        case 1:
            ans[n]='R';
            break;
        case 2:
            ans[n]='U';
            break;
        case 3:
            ans[n]='D';
            break;
        }
        tt=a[tt].head;
    }
    Map[20][20]='A'; Map[20][22]='A';
    for (int i=n; i>0; i--) printf("%c",ans[i]); printf("\n");
    for (int i=1; i<=20; i++)
    {
        for (int j=1; j<=41; j++) cout<<Map[i][j];
        cout<<endl;
    }
    return;
}
void find()
{
    h=1,t=1;
    a[h].xl=20; a[h].yl=20; a[h].xr=20; a[h].yr=22;
    a[h].sum=0; a[h].head=0;  a[h].step=-1;
    f[20][20][20][22]=true;
    while (h<=t)
    {
        for (int i=0; i<4; i++)
        {
            int xll,yll,xrr,yrr;
            xll=a[h].xl+ldx[i], yll=a[h].yl+ldy[i], xrr=a[h].xr+rdx[i], yrr=a[h].yr+rdy[i];
            if (xll<1 || xll>20 || yll<1 || yll>20 || Map[xll][yll]=='#')
            {
                xll=a[h].xl; yll=a[h].yl;
            }
            if (xrr<1 || xrr>20 || yrr<22 || yrr>41 || Map[xrr][yrr]=='#')
            {
                xrr=a[h].xr; yrr=a[h].yr;
            }
            if (!f[xll][yll][xrr][yrr])
            {
                t++;
                a[t].xl=xll;a[t].yl=yll;a[t].xr=xrr;a[t].yr=yrr;
                a[t].head=h;a[t].step=i;a[t].sum=a[h].sum+1;
                f[xll][yll][xrr][yrr]=true;
                if (xll==1 && yll==20 && xrr==1 && yrr==22)
                {
                    print(t);
                    return;
                }
            }
        }
        //cout<<endl;
        h++;
        //if (h>100) return;
    }
    //cout<<t<<endl;
    return;
}
int main()
{
    for (int i=1; i<=20; i++)
    {
        for (int j=1; j<=41; j++)
            Map[i][j]=getchar();
        getchar();
    }
    find();
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值