其实是很水的一道bfs题,昨晚比赛的时候没看清题意,漏了一个条件。

 #include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<vector>
#define maxn
#define INF 1000000000
using namespace std;
int vist[][];
char str[][];
int dirx[]={-,,,};
int diry[]={,,,-};
int m,n,stx,sty,edx,edy;
int judge(int x,int y)
{
if(x>=&&x<n&&y>=&&y<m)
return ;
return ;
}
int bfs()
{
queue<int> q;
stx--;
sty--;edx--;edy--;
int num=stx*m+sty;
q.push(num);
//vist[stx][sty]--;就改的这个地方,因为起点和终点有可能相同
while(!q.empty())
{
num=q.front();
//printf("%d==\n",num);
q.pop();
int xx=num/m;
int yy=num%m; for(int i=;i<;i++)
{
int newx=xx+dirx[i];
int newy=yy+diry[i];
if(newx==edx&&newy==edy&&vist[newx][newy]==)
return ;
if(judge(newx,newy)&&vist[newx][newy]>)
{
q.push(newx*m+newy);
vist[newx][newy]--;
}
}
}
//printf("==\n");
return ; }
int main()
{
scanf("%d %d",&n,&m);
for(int i=;i<n;i++)
scanf("%s",str[i]);
scanf("%d %d",&stx,&sty);
scanf("%d %d",&edx,&edy);
for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
if(str[i][j]=='X')
vist[i][j]=;
else
vist[i][j]=;
}
}
if(bfs())
printf("YES\n");
else
printf("NO\n");
return ;
}

Codeforces Round #301 (Div. 2) B. School Marks的更多相关文章

  1. 贪心 Codeforces Round #301 (Div. 2) B. School Marks

    题目传送门 /* 贪心:首先要注意,y是中位数的要求:先把其他的都设置为1,那么最多有(n-1)/2个比y小的,cnt记录比y小的个数 num1是输出的1的个数,numy是除此之外的数都为y,此时的n ...

  2. Codeforces Round #301 (Div. 2) B. School Marks 构造/贪心

    B. School Marks Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/540/probl ...

  3. DFS/BFS Codeforces Round #301 (Div. 2) C. Ice Cave

    题目传送门 /* 题意:告诉起点终点,踩一次, '.'变成'X',再踩一次,冰块破碎,问是否能使终点冰破碎 DFS:如题解所说,分三种情况:1. 如果两点重合,只要往外走一步再走回来就行了:2. 若两 ...

  4. 贪心 Codeforces Round #301 (Div. 2) A. Combination Lock

    题目传送门 /* 贪心水题:累加到目标数字的距离,两头找取最小值 */ #include <cstdio> #include <iostream> #include <a ...

  5. 「日常训练」School Marks(Codeforces Round 301 Div.2 B)

    题意与分析(CodeForces 540B) 题意大概是这样的,有一个考试鬼才能够随心所欲的控制自己的考试分数,但是有两个限制,第一总分不能超过一个数,不然就会被班里学生群嘲:第二分数的中位数(科目数 ...

  6. 【Codeforces Round #301 (Div. 2) B】 School Marks

    [链接] 我是链接,点我呀:) [题意] 已知k门成绩. 总共有n门成绩. 让你构造剩下的n-k门成绩,使得这n门成绩的中位数>=y,并且这n门成绩的和要小于等于x. n为奇数 [题解] 首先判 ...

  7. Codeforces Round #301 (Div. 2)(A,【模拟】B,【贪心构造】C,【DFS】)

    A. Combination Lock time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...

  8. CodeForces Round #301 Div.2

    今天唯一的成果就是把上次几个人一起开房打的那场cf补一下. A. Combination Lock 此等水题看一眼样例加上那个配图我就明白题意了,可是手抽没有注释掉freopen,WA了一发. #in ...

  9. Codeforces Round #301 (Div. 2)A B C D 水 模拟 bfs 概率dp

    A. Combination Lock time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

随机推荐

  1. Could not find artifact com.sun:tools:jar:1.5.0

    问题: Failed to execute goal on project petroleum: Could not resolve dependencies for project petroleu ...

  2. 胡扯两句——CDQ分治

    之前听大神讲过CDQ分治大概是个什么东西,但是一直还没有真正去搞过.今天稍微看了一下,写点自己的理解. 首先CDQ分治有两个条件. 条件1:可以分成两个独立互不影响的问题(这里的"独立&qu ...

  3. 浅析Oracle范式的概念(转载)

    范式:英文名称是 Normal Form,它是英国人 E.F.Codd(关系数据库的老祖宗)在上个世纪70年代提出关系数据库模型后总结出来的,范式是关系数据库理论的基础,也是我们在设计数据库结构过程中 ...

  4. 凭借K2 SmartObject框架,在SharePoint中集成数据

    随着SharePoint 2013的发布,Microsoft已提供Business Connectivity Services(BCS)增强功能以及外部列表功能,确保您可以更简单地在SharePoin ...

  5. <转载>DB2常用命令

    1.数据库的启动.停止    db2start --启动   db2stop [force] --停止 2.与数据库的连接.断开   db2 CONNECT TO DBName [user UserI ...

  6. js中获取项目路径的小插件

    //立即执行的js (function() { //获取contextPath var contextPath = getContextPath(); //获取basePath var basePat ...

  7. ASP.NET MVC4 & Entity Framework 6.0 IIS 部署出错解决方案

    博客地址 http://blog.csdn.net/foxdave 近期了解MVC4的时候弄了一个简单的小工程,使用Entity Framework作为Model,F5启动调试运行的时候没有问题,但是 ...

  8. C# CsvFile 类

    using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Tex ...

  9. Jquery Table 操作

    获取行号 var rowIndex = $("#TableId").find("tr").index($("#RowId")[0]); va ...

  10. <转>thinkphp自动验证无效的问题

    新手入门thinkphp,试用自动验证表单输入数据功能,却发现怎么都不能调用自动验证,自动验证无效,原因竟是一个小细节的疏忽,学习一定要细心啊! Action方法: IndexAction下的adds ...