Codeforces Round #290 (Div. 2)


B. Fox And Two Dots  http://codeforces.com/contest/510/problem/B

简单的DFS

#include<iostream>
#include<string.h>
using namespace std;

char st[55][55];
int vis[55][55]  , turn[4][2] ={0,1,0,-1,1,0,-1,0};
int n , m , flag;

void dfs(int x , int y , char ch, int limit)
{
     if(flag)  return;
     vis[x][y] = 1;
     for(int i = 0 ; i < 4 ; i++)
     {
          if(limit == i)
               continue;
          int xx = turn[i][0] + x;
          int yy = turn[i][1] + y;
          if(xx >= 0 && yy >= 0 && xx < n && yy < m && st[xx][yy] == ch)
          {
               if(vis[xx][yy] == 1)
               {
                    flag = 1; return;
               }
               else
               {
                    if(i == 1)
                         dfs(xx,yy,ch,0);
                    if(i == 0)
                         dfs(xx,yy,ch,1);
                    if(i == 2)
                         dfs(xx,yy,ch,3);
                    if(i == 3)
                         dfs(xx,yy,ch,2);
               }
          }
     }
}

int main()
{
     cin >> n >> m;
     for(int i = 0 ; i < n ; i++)
          cin >>st[i];
     for(int i = 0 ; i < n ;i++)
          for(int j = 0 ; j < m ; j++)
          {
               memset(vis,0,sizeof(vis));
               dfs(i,j,st[i][j],-1);
               if(flag)
               {
                    cout << "Yes" << endl;
                    return 0;
               }
          }
     cout << "No" <<endl;
     return 0;
}


A. Fox And Snake http://codeforces.com/contest/510/problem/A

签名题 输出蛇

#include<iostream>
using namespace std;
int main()
{
     int n , m ;
     while(cin >> n >> m)
     {
          for(int i = 1 ; i <= n ;i++)
          {
               for(int j = 1 ; j <= m ;j++)
               {
                    if(i%2)
                         cout << "#" ;
                    else
                    {
                         if(i%4 == 0 && j == 1)
                              cout << "#" ;
                         else if(i%2 == 0 && j == m && i%4 !=0)
                              cout << "#" ;
                         else
                              cout << ".";
                    }
               }

               cout << endl;
          }
     }
     return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值