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

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

 #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. iOS sourceTree忽略掉必要的xcuserdata文件

    1.找到git对应的文件 git status 结果 会得到已经修改的文件. modified: Zing.xcodeproj/xcuserdata/tiny.xcuserdatad/xcscheme ...

  2. iOS voip电话和sip软电话 --网络电话

    一|介绍1.两者区别: SIP软电话与IP电话在技术上属于同一类型,只是SIP软电话是使用电脑软件实现的,而IP电话有一部分是在话机中直接写入了程序,可以通过硬件直接使用.IP(简称VoIP,源自英语 ...

  3. iOS常见的几种加密方法(base64.MD5.Token传值.系统指纹验证。。加密)

    普通加密方法是讲密码进行加密后保存到用户偏好设置中 钥匙串是以明文形式保存,但是不知道存放的具体位置 一. base64加密 base64 编码是现代密码学的基础 基本原理: 原本是 8个bit 一组 ...

  4. Git常用命令清单笔记

    git github 小弟调调 2015年01月12日发布 赞  |   6收藏  |  45 5k 次浏览 这里是我的笔记,记录一些git常用和一些记不住的命令,这个笔记原本是基于 颜海镜的文章增加 ...

  5. Chrome调试折腾记_(1)调试控制中心快捷键详解!!!

    转载:http://blog.csdn.net/crper/article/details/48098625 大多浏览器的调试功能的启用快捷键都一致-按下F12;还是熟悉的味道;  或者直接 Ctrl ...

  6. Docker(九):Docker容器卷插件

    1.Convoy 1.1 安装 [root@MediaServer tmp]# tar xvf convoy.tar.gz convoy/ convoy/convoy-pdata_tools conv ...

  7. readAsDataURL(file) & readAsText(file, encoding)

      readAsDataURL(file)会把文件内容转换为data类型的URL: data:text/plain;base64,b3JkZXItaWQJb3JkZXItaXRlbS1p... 这种d ...

  8. golang社区

    a development list for Go Programming Language https://groups.google.com/forum/#!forum/golang-dev a ...

  9. windows server数据库备份

    @echo off //设置生成文件名字 set "Ymd=%date:~,4%%date:~5,2%%date:~8,2%"//使用mysqldump输出sql文件 cesec ...

  10. thinkinginjava学习笔记09_内部类

    定义与创建 将一个类定义放在另一个类.方法.作用域.匿名类等地方,就是内部类:内部类只能由外部类对象创建(通过外部方法或者.new方法),内部类对象创建时必须已经有一个外部类对象,并且与之连接(在内部 ...