Codeforces Round #301 (Div. 2) B. School Marks
其实是很水的一道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的更多相关文章
- 贪心 Codeforces Round #301 (Div. 2) B. School Marks
题目传送门 /* 贪心:首先要注意,y是中位数的要求:先把其他的都设置为1,那么最多有(n-1)/2个比y小的,cnt记录比y小的个数 num1是输出的1的个数,numy是除此之外的数都为y,此时的n ...
- 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 ...
- DFS/BFS Codeforces Round #301 (Div. 2) C. Ice Cave
题目传送门 /* 题意:告诉起点终点,踩一次, '.'变成'X',再踩一次,冰块破碎,问是否能使终点冰破碎 DFS:如题解所说,分三种情况:1. 如果两点重合,只要往外走一步再走回来就行了:2. 若两 ...
- 贪心 Codeforces Round #301 (Div. 2) A. Combination Lock
题目传送门 /* 贪心水题:累加到目标数字的距离,两头找取最小值 */ #include <cstdio> #include <iostream> #include <a ...
- 「日常训练」School Marks(Codeforces Round 301 Div.2 B)
题意与分析(CodeForces 540B) 题意大概是这样的,有一个考试鬼才能够随心所欲的控制自己的考试分数,但是有两个限制,第一总分不能超过一个数,不然就会被班里学生群嘲:第二分数的中位数(科目数 ...
- 【Codeforces Round #301 (Div. 2) B】 School Marks
[链接] 我是链接,点我呀:) [题意] 已知k门成绩. 总共有n门成绩. 让你构造剩下的n-k门成绩,使得这n门成绩的中位数>=y,并且这n门成绩的和要小于等于x. n为奇数 [题解] 首先判 ...
- 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 ...
- CodeForces Round #301 Div.2
今天唯一的成果就是把上次几个人一起开房打的那场cf补一下. A. Combination Lock 此等水题看一眼样例加上那个配图我就明白题意了,可是手抽没有注释掉freopen,WA了一发. #in ...
- 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 ...
随机推荐
- Spring mvc中使用request和response
@ResponseBody @RequestMapping(value="/ip", method=RequestMethod.GET) public String getIP(H ...
- 第四章 CSS基础
1.CSS是cascading style sheets 层叠样式表.样式定义如何显示html元素,通常存储在样式表中,将样式添加到html中,是为了解决内容与表现分离的问题. 2.外部样式表可以极大 ...
- 部分SIM卡被曝存安全漏洞:7.5亿部手机受牵连
7月22日消息,据国外媒体报道,一安全研究人员发现部分移动SIM卡所使用的加密方式存在一个安全漏洞,可能会导致手机被黑客远程控制. DES数据加密标准的SIM卡——DES是一种较旧的标准,目前正被部分 ...
- python错误集锦
1.lt与list等同,不能作为变量名 2.中文路径名:os.path.normcase(filepath) 如果遇到 ascii码在路径某处不能转换, 那么 filepath.encode('gbk ...
- hdu 4611 Balls Rearrangement
http://acm.hdu.edu.cn/showproblem.php?pid=4611 从A中向B中移动和从B中向A中移动的效果是一样的,我们假设从B中向A中移动 而且A>B 我们先求出所 ...
- 戴文的Linux内核专题:03驱动程序
转自Linux中国 驱动程序是使内核能够沟通和操作硬件或协议(规则和标准)的小程序.没有驱动程序,内核不知道如何与硬件沟通或者处理协议(内核实际上先发送指令给BIOS,然后BIOS传给硬件). Lin ...
- Program C 暴力求解
Description A ring is composed of n (even number) circles as shown in diagram. Put natural numbers ...
- 各种注释--------html,jsp
1. <!--到梦之都XHTML教程的链接--> <a href="http://www.dreamdu.com/xhtml/"> 学习XHTML < ...
- Keil 4.0 生成bin文件
在菜单:Flash /configuare falsh tools ... option for Tatget '项目' /User中:在Run User Programs After Build/R ...
- iphone判断当前网络连接类型
eachability只能区分出无网络.wifi和wwan(2G&2.5G&3G)类型的网络连接类型,只需重构networkStatusForFlags方法,即可详细区分出2G与3G网 ...