首页 > 其他分享 >hdu-2821

hdu-2821

时间:2023-03-03 13:02:10浏览次数:60  
标签:hdu return int char num && include 2821

http://acm.hdu.edu.cn/showproblem.php?pid=2821


不要被题目吓到 ,认真读题还是好理解的


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<ctype.h>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<set>

using namespace std;

int n,m;
int p[30][30];
char c;
int num = 0,ok;

int dir[4][2] = {{-1,0},{1,0},{0,-1},{0,1}};
char dirc[5] = {'U','D','L','R'};

char step[1000];
char str[33];

int check (int x,int y)
{
	if (x >= 0 && x < m && y >= 0 && y < n)
		return 1;
	return 0;
}

int dfs (int x,int y,int s)
{
	if (s >= num)
	{
		step[s]=0;
		return 1;
	}

	for(int i =0;i<4;i++)
	{
		int xx = x + dir[i][0];
		int yy = y + dir[i][1];

		if ( p[ xx ][ yy ] !=0 || !check ( xx ,yy ) )
			continue;

		while (  p[ xx ][ yy  ] == 0 && check ( xx ,yy ))
		{
			xx+=dir[i][0];
			yy+=dir[i][1];
		}

		if (!check(xx+dir[i][0] ,yy+dir[i][1] ))
			continue;

		int tmp = p[xx][yy];

		p[xx+dir[i][0]][yy+dir[i][1]] += (tmp-1);
		p[xx][yy] =0;

		step[s] = dirc[i];

		if ( dfs(xx,yy,s+1) )
			return 1;

		p[xx+dir[i][0]][yy+dir[i][1]] -= (tmp-1);
		p[xx][yy] = tmp;
	}
	return 0;
}


int main ()
{
	while (cin>>n>>m)
	{
		num = 0;
	
		for(int i=0;i<m;i++)
		{
            scanf("%s",str);
            for(int j=0;j<n;j++)
			{
                if(str[j]!='.')
				{
                    num += str[j]-'a'+1;
                    p[i][j]=str[j]-'a'+1;
                }
				else 
                    p[i][j]=0;
            }
         }


		ok = 0;

		for(int i=0;i<m;i++)
		{
				for(int j=0;j<n;j++)
				{
					if (!p[i][j] && dfs(i,j,0) )
					{
						ok = 1;
						cout<<i<<endl;
						cout<<j<<endl;
						cout<<step<<endl;
						break;
					}
				}
			if (ok)
				break;
		}

	}
	return 0;
}


标签:hdu,return,int,char,num,&&,include,2821
From: https://blog.51cto.com/u_15990681/6098484

相关文章

  • HDU-5112-A Curious Matt (2014ACM/ICPC北京赛区现场赛A题!)
    http://acm.hdu.edu.cn/showproblem.php?pid=5112排序之后计算就好开始用cin超时了#include<stdio.h>#include<iostream>#include<math.h>#include<stdlib.h>#......
  • hdu-5122
    http://acm.hdu.edu.cn/showproblem.php?pid=5122简单题#include<stdio.h>#include<iostream>#include<math.h>#include<stdlib.h>#include<ctype.h>#include......
  • HDUOJ 2041-2055
    2041超级楼梯ProblemDescription有一楼梯共M级,刚开始时你在第一级,若每次只能跨上一级或二级,要走上第M级,共有多少种走法? Input输入数据首先包含一个整数N,表示测试实......
  • Problem C HDU - 5687
    现在有个字典要支持一下操作 1、insert:往神奇字典中插入一个单词  2、delete:在神奇字典中删除所有前缀等于给定字符串的单词  3、search:查询是否在神奇......
  • 统计难题 HDU - 1251
     给一些字符串,问以某个串为前缀的串有几个 #include<iostream>#include<algorithm>#include<cstring>usingnamespacestd;constintN=5e5+4;charnum[80]......
  • Reading comprehension HDU - 4990
    ans=0;   for(i=1;i<=n;i++)    {     if(i&1)ans=(ans*2+1)%m;     elseans=ans*2%m;    } ......
  • HDU 4081 Qin Shi Huang's National Road System(次小树,4级)
    A- QinShiHuang'sNationalRoadSystemTimeLimit:1000MS     MemoryLimit:32768KB     64bitIOFormat:%I64d&%I64uSubmit ​​Status​​......
  • hdu 4284 Travel(压缩DP,4级)
    TravelTimeLimit:10000/5000MS(Java/Others)    MemoryLimit:32768/32768K(Java/Others)TotalSubmission(s):2641    AcceptedSubmission(s):724......
  • hdu 2608 0 or 1(数论)
    0or1TimeLimit:6000/2000MS(Java/Others)    MemoryLimit:32768/32768K(Java/Others)TotalSubmission(s):1659    AcceptedSubmission(s):418Pro......
  • HDU 2888 Check Corners (二维RMQ,3级)
    A-CheckCornersCrawlinginprocess...CrawlingfailedTimeLimit:10000MS    MemoryLimit:32768KB    64bitIOFormat:%I64d&%I64u​​Submit......