每次到达一个点,或者点亮一个房间的灯的时候,检查一下它四周的点能否走。

  一开始看错题了..要求的是最多能开多少房的灯。

 #include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn=;
const int xx[]={,,,-},yy[]={,-,,};
struct zs{int too,pre;}e[];int tot,last[maxn];
int dlx[maxn],dly[maxn];
int id[][],X[maxn],Y[maxn];
bool con[][],can[][];
int i,j,k,n,m,l,r;
int ans; int ra;char rx;
inline int read(){
rx=getchar(),ra=;
while(rx<''||rx>'')rx=getchar();
while(rx>=''&&rx<='')ra*=,ra+=rx-,rx=getchar();return ra;
}
inline void insert(int a,int b){e[++tot].too=b,e[tot].pre=last[a],last[a]=tot;}
inline void run(int nx,int ny){
int x,y;
for(int i=;i<;i++){
x=nx+xx[i],y=ny+yy[i];
if(x<||y<||x>n||y>n)continue;
if(!con[x][y]&&can[x][y])r++,dlx[r]=x,dly[r]=y;
con[x][y]=;
}
}
int main(){
n=read(),m=read();int a,b,c,d,cnt=;
for(i=;i<=n;i++)for(j=;j<=n;j++)id[i][j]=++cnt,X[cnt]=i,Y[cnt]=j;
for(i=;i<=m;i++)a=read(),b=read(),c=read(),d=read(),insert(id[a][b],id[c][d]);
l=,r=;
dlx[]=dly[]=con[][]=can[][]=;
while(l<r){
l++;
for(i=last[id[dlx[l]][dly[l]]];i;i=e[i].pre){
if(!can[X[e[i].too]][Y[e[i].too]]&&con[X[e[i].too]][Y[e[i].too]])
r++,dlx[r]=X[e[i].too],dly[r]=Y[e[i].too];
can[X[e[i].too]][Y[e[i].too]]=;
}
run(dlx[l],dly[l]);
}
for(i=;i<=n;i++)for(j=;j<=n;j++)if(can[i][j])ans++;
printf("%d\n",ans);
}

4395: [Usaco2015 dec]Switching on the Lights的更多相关文章

  1. bzoj4395[Usaco2015 dec]Switching on the Lights*

    bzoj4395[Usaco2015 dec]Switching on the Lights 题意: n*n个房间,奶牛初始在(1,1),且只能在亮的房间里活动.每当奶牛经过一个房间,就可以打开这个房 ...

  2. BZOJ 4390: [Usaco2015 dec]Max Flow

    4390: [Usaco2015 dec]Max Flow Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 177  Solved: 113[Submi ...

  3. 【BZOJ4391】[Usaco2015 dec]High Card Low Card(贪心)

    [BZOJ4391][Usaco2015 dec]High Card Low Card(贪心) 题面 BZOJ 题解 预处理前缀后缀的结果,中间找个地方合并就好了. #include<iostr ...

  4. bzoj 4397: [Usaco2015 dec]Breed Counting -- 前缀和

    4397: [Usaco2015 dec]Breed Counting Time Limit: 10 Sec  Memory Limit: 128 MB Description Farmer John ...

  5. [Usaco2015 dec]Max Flow 树上差分

    [Usaco2015 dec]Max Flow Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 353  Solved: 236[Submit][Sta ...

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

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

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

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

  8. bzoj4393: [Usaco2015 Dec]Fruit Feast

    题意: T,A,B.T是上限.A和B可以随意吃但是不能超过T.有一次将吃的东西/2的机会.然后可以继续吃,不能超过T.问最多可以吃多少. =>我们先处理不能/2可以吃到哪些.然后弄个双指针扫一扫 ...

  9. BZOJ4390: [Usaco2015 dec]Max Flow

    BZOJ4390: [Usaco2015 dec]Max Flow Description Farmer John has installed a new system of N−1 pipes to ...

随机推荐

  1. Spring入门篇总结:

    本文是对慕课网上"搞定SSM开发"路径的系列课程的总结,详细的项目文档和课程总结放在github上了.点击查看 视频传送门:Spring入门篇 该门课程主要从Spring的Bean ...

  2. 模板引擎(smarty)知识点总结三

    阔别了几个月,小杨又来分享php知识.话不多说,言归正传,今天继续带来smarty的知识点. -----------------smarty  assign append 详解 对于这两个的区别和联系 ...

  3. OpenStack运维(一):OpenStack项目和用户

    1.添加项目 keystone tenant-create --name=demo [--description tenant-description --enable false] demo:项目名 ...

  4. 用python在excel中读取与生成随机数写入excel中

    今天是我第一次发博客,就关于python在excel中的应用作为我的第一篇吧. 具体要求是:在一份已知的excel表格中读取学生的学号与姓名,再将这些数据放到新的excel表中的第一列与第二列,最后再 ...

  5. 从源码(编译)安装golang

    从源码安装golang 通常情况下,安装go只需要在官网(https://golang.org/dl/)下载适合系统的二进制发布包,按照安装说明进行安装即可. 对于Linux, Mac OS X和Fr ...

  6. Linux(CentOS6.5)下修改Nginx初始化配置

    本文地址http://comexchan.cnblogs.com/,作者Comex Chan,尊重知识产权,转载请注明出处,谢谢! 首先备份相关文件: cp /comexHome/nginx/conf ...

  7. 操作Frame和IFrame中页面元素

    HTML <iframe> 标签 定义:iframe 元素会创建包含另外一个文档的内联框架(即行内框架). frame标签有frameset.frame.iframe三种,frameset ...

  8. Tomcat安装和目录简介

    要知道动态的网页必须要有服务器的支撑! 1.知名的java web服务器 Tomcat:Apache组织发布,免费开源的,轻量级 JBoss.WebLogic是商用的,价格较高,但相对于开源的更加稳定 ...

  9. HY.Mail:C#简单、易用的邮件工具库

    一.开发HY.Mail的初衷 Nuget或者github上有很多成熟且优秀的邮件库可以使用, 但是目前找到的使用都不够简洁或者不适合我的使用场景 我的场景是开发应用场景(例如系统通知.运维通知),而非 ...

  10. Vue 爬坑之路(九)—— 用正确的姿势封装组件

    迄今为止做的最大的 Vue 项目终于提交测试,天天加班的日子终于告一段落... 在开发过程中,结合 Vue 组件化的特性,开发通用组件是很基础且重要的工作 通用组件必须具备高性能.低耦合的特性 为了满 ...