传送门

题目大意:n*n的网格,每个网格是一个房间

都关着灯,只有(1,1)开着灯,且(x,y)有着(z,k)房间灯的开关。

问从(1,1)开始走最多点开几盏灯。

题解:搜索+骗分。

劳资的骗分天下无敌,劳资的骗分世界第一

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<vector>
#define N 102
using namespace std; int n,m,ans=,js; int vis[N][N],b[N][N],ok[N][N]; int mx[]={,,-,},
my[]={,,,-}; struct node{
int x,y;
}; struct T{
int x,y;
}; queue<T>q; vector<node>a[N][N]; void bfs(){
T c;c.x=;c.y=;q.push(c);
vis[][]=true;b[][]=true;
while(!q.empty()){
T now=q.front();q.pop();js++;
if(js==n*n*)return; //遍历了这么多遍应该灯应该都开了吧。
int xx=now.x,yy=now.y;
for(int i=;i<a[xx][yy].size();i++){
node g=a[xx][yy][i];
if(b[g.x][g.y]==)ans++;
b[g.x][g.y]=true;
}
for(int i=;i<;i++){
int nx=xx+mx[i],ny=yy+my[i];
if(nx<||nx>n||ny<||ny>n||vis[nx][ny]||b[nx][ny]==) continue;
vis[nx][ny]=true;
T tmp;tmp.x=nx;tmp.y=ny;
q.push(tmp);
}
q.push(now);
}
} int main(){
scanf("%d%d",&n,&m);
for(int i=;i<=m;i++){
int x,y,nx,ny;
scanf("%d%d%d%d",&x,&y,&nx,&ny);
node t;t.x=nx;t.y=ny;
a[x][y].push_back(t);
}
bfs();
printf("%d\n",ans);
return ;
}

AC

骗分归骗分正解还是要学的

每点开一盏灯,看这盏灯的上下左右是否被点开灯了

有被点开的就开始搜这个点。

洛谷 P2828 Switching on the Lights(开关灯)的更多相关文章

  1. 洛谷P2828 Switching on the Lights(开关灯)

    P2828 Switching on the Lights(开关灯) 题目背景 来源:usaco-2015-dec Farm John 最近新建了一批巨大的牛棚.这些牛棚构成了一个N*N的矩形网络.( ...

  2. 搜索【洛谷P2845】 [USACO15DEC]Switching on the Lights 开关灯

    P2845 [USACO15DEC]Switching on the Lights 开关灯 题目背景 来源:usaco-2015-dec Farm John 最近新建了一批巨大的牛棚.这些牛棚构成了一 ...

  3. Luogu P2845 [USACO15DEC]Switching on the Lights 开关灯(bfs)

    P2845 [USACO15DEC]Switching on the Lights 开关灯 题意 题目背景 来源:usaco-2015-dec \(Farm\ John\)最近新建了一批巨大的牛棚.这 ...

  4. P2845 [USACO15DEC]Switching on the Lights 开关灯

    题目背景 来源:usaco-2015-dec Farm John 最近新建了一批巨大的牛棚.这些牛棚构成了一个N*N的矩形网络.(1<n<100) 然而bessie十分怕黑,他想计算可以把 ...

  5. luogu P2828 Switching on the Lights(开关灯)

    题目背景 来源:usaco-2015-dec Farm John 最近新建了一批巨大的牛棚.这些牛棚构成了一个N*N的矩形网络.(1<n<100) 然而bessie十分怕黑,他想计算可以把 ...

  6. 「Luogu P2845 [USACO15DEC]Switching on the Lights 开关灯」

    USACO的又一道搜索题 前置芝士 BFS(DFS)遍历:用来搜索.(因为BFS好写,本文以BFS为准还不是因为作者懒) 链式前向星,本题的数据比较水,所以邻接表也可以写,但是链式前向星它不香吗. 具 ...

  7. 洛谷P2845-Switching on the Lights 开关灯

    Problem 洛谷P2845-Switching on the Lights 开关灯 Accept: 154    Submit: 499Time Limit: 1000 mSec    Memor ...

  8. COCI2017-2018#3 Dojave || 洛谷P4443

    题目传送门............................................................................................... ...

  9. 洛谷1640 bzoj1854游戏 匈牙利就是又短又快

    bzoj炸了,靠离线版题目做了两道(过过样例什么的还是轻松的)但是交不了,正巧洛谷有个"大牛分站",就转回洛谷做题了 水题先行,一道傻逼匈牙利 其实本来的思路是搜索然后发现写出来类 ...

随机推荐

  1. AsyncCallback 异步回调委托

    js是单线程语言,单线程就意味着,所有任务需要排队,前一个任务结束,才会执行后一个任务.如果前一个任务耗时很长,后一个任务就不得不一直等着. 如果排队是因为计算量大,CPU忙不过来,倒也算了,但是很多 ...

  2. Effective C++学习笔记(1)

    最近刚看完Effective C++,记录一下当前几个比较常用的方法. 1.以独立语句将newed对象置入智能指针 智能指针是以对象管理资源,在构造函数中获得资源并在析构函数中释放资源​ 以下调用:​ ...

  3. underscore || lodash

    1.http://www.css88.com/archives/5443 (underscore) let list = _.filter(record.orderGoodsList, item =& ...

  4. no persistent classes found for query class: FROM com.vrv.paw.domain.User

    在整合Spring+Hibernate时报该错误,sessionFactory配置如下: <bean id="sessionFactory" class="org. ...

  5. shiro:10个过滤器;10个jsp标签;5个@注解

    10个过滤器 过滤器简称 对应的java类 anon org.apache.shiro.web.filter.authc.AnonymousFilter authc org.apache.shiro. ...

  6. yyyy-MM-dd EEE hh:mm:ss(日期转换)

    <script> /** * 对Date的扩展,将 Date 转化为指定格式的String * 月(M).日(d).12小时(h).24小时(H).分(m).秒(s).周(E).季度(q) ...

  7. hdu3549

    题解: 网络流模板题 多组数据 代码: #include<cstdio> #include<cstring> #include<algorithm> #includ ...

  8. PHP stripos()、strripos()和strrpos() 使用方法和区别

    区别 stripos():查找字符串首次出现的位置(不区分大小写) 写法:stripos ( string $haystack , string $needle [, int $offset = 0 ...

  9. 使用 create-react-app 构建 react应用程序

    原文 http://blog.csdn.net/github_squad/article/details/57452333#

  10. 初识jQuery(2)

    1.DOM模型 1.1以对象描述文档的方式就是DOM 节点对象就是被称为DOM对象(标签对象) 1.2节点 元素节点(标签) 文本节点(标签内容) 属性节点(标签属性) 2.Jquery语法结构 $( ...