第四十四场Acwing周赛

1.不同正整数的个数

 

 题解思路:这题用y总的话来说就是一道大水题,很多方法,我直接放上我的代码仅供参考吧。

#include<bits/stdc++.h>
using namespace std;
int st[1000];
int main()
{
    int cnt;
    int n,a[1000];
   cin>>n;
    for(int i=0;i<n;i++)
    { 
        cin>>a[i];
        st[a[i]]=1;
    }
  
  for(int i=1;i<610;i++)
  {
      if(st[i]==1)cnt++;
  }
    cout<<cnt<<endl;
    return 0;
}

 2.最短路径

 

 题解思路:这题一看就是BFS,不过要注意边界问题,要满足两种情况,1.不能有环,这样会影响最短路的判断,2路径间不能相邻,除了路劲移动时相连的之外

 

#include<bits/stdc++.h>
using namespace std;
const int  N=210, B=N/2;
int dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
bool st[N][N];//判重数组
int get(char c)
{
     if(c=='U')return 0;
     if(c=='R')return 1;
     if(c=='D')return 2;
     return 3;
}
int main()
{
    string str;
    cin>>str;
    int x=B,y=B;
    bool res=true;
    st[x][y]=true;
    for(auto c:str)
    {
        int d=get(c);
        x+=dx[d],y+=dy[d];
        if(st[x][y])res=false;
        for(int i=0;i<4;i++)
         if(i!=(d^2)&&st[x+dx[i]][y+dy[i]])//d^2表示方向取反
           res=false;
           st[x][y]=true;
    }
    if(res)puts("YES");
    else puts("NO");
    return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值