4395: [Usaco2015 dec]Switching on the Lights
每次到达一个点,或者点亮一个房间的灯的时候,检查一下它四周的点能否走。
一开始看错题了..要求的是最多能开多少房的灯。
#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的更多相关文章
- bzoj4395[Usaco2015 dec]Switching on the Lights*
bzoj4395[Usaco2015 dec]Switching on the Lights 题意: n*n个房间,奶牛初始在(1,1),且只能在亮的房间里活动.每当奶牛经过一个房间,就可以打开这个房 ...
- BZOJ 4390: [Usaco2015 dec]Max Flow
4390: [Usaco2015 dec]Max Flow Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 177 Solved: 113[Submi ...
- 【BZOJ4391】[Usaco2015 dec]High Card Low Card(贪心)
[BZOJ4391][Usaco2015 dec]High Card Low Card(贪心) 题面 BZOJ 题解 预处理前缀后缀的结果,中间找个地方合并就好了. #include<iostr ...
- bzoj 4397: [Usaco2015 dec]Breed Counting -- 前缀和
4397: [Usaco2015 dec]Breed Counting Time Limit: 10 Sec Memory Limit: 128 MB Description Farmer John ...
- [Usaco2015 dec]Max Flow 树上差分
[Usaco2015 dec]Max Flow Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 353 Solved: 236[Submit][Sta ...
- 搜索【洛谷P2845】 [USACO15DEC]Switching on the Lights 开关灯
P2845 [USACO15DEC]Switching on the Lights 开关灯 题目背景 来源:usaco-2015-dec Farm John 最近新建了一批巨大的牛棚.这些牛棚构成了一 ...
- 洛谷P2828 Switching on the Lights(开关灯)
P2828 Switching on the Lights(开关灯) 题目背景 来源:usaco-2015-dec Farm John 最近新建了一批巨大的牛棚.这些牛棚构成了一个N*N的矩形网络.( ...
- bzoj4393: [Usaco2015 Dec]Fruit Feast
题意: T,A,B.T是上限.A和B可以随意吃但是不能超过T.有一次将吃的东西/2的机会.然后可以继续吃,不能超过T.问最多可以吃多少. =>我们先处理不能/2可以吃到哪些.然后弄个双指针扫一扫 ...
- BZOJ4390: [Usaco2015 dec]Max Flow
BZOJ4390: [Usaco2015 dec]Max Flow Description Farmer John has installed a new system of N−1 pipes to ...
随机推荐
- 人工智能技术实践篇:espeak开发环境调试
一.前言 1.espeak版本: espeak-1.48.04-source 2.开发环境:VC+2015 二.正文 2.1 错误提示 LNK1104: cannot open file 'LIBC. ...
- Swift tableview自带的刷新控件
import UIKit class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource { let ...
- ABP 用swagger UI测试API报401无权限访问问题
问题描述: 当我们用swagger UI对Web API 进行测试时报401错误 我们点开GET /api/services/app/Role/GetAll,输入参数 点击Try it out!按钮, ...
- 瞎j8封装第二版之数据层的封装
看了以前写的代码,对就是下面这个 手把手封装数据层之DataUtil数据库操作的封装 觉得以前写的代码好烂啊!!!,重新理了一下思路,写得更规范和简练,应该效率也会高很多,用了一下下午写的连接池(半废 ...
- spring boot + Thymeleaf开发web项目
"Spring boot非常适合Web应用程序开发.您可以轻松创建自包含的HTTP应用.web服务器采用嵌入式Tomcat,或者Jetty等.大多数情况下Web应用程序将使用 spring- ...
- ES6 字符串的扩展
字符的Unicode表示法 JavaScript允许采用\uXXXX形式表示一公分字符,其中XXXX表示字符的码点. "\u0061" //"a" 但是,这种表 ...
- w 命令详解
作用: 用于显示已经登录系统的用户列表, 并显示用户正在执行的指令. 执行这个命令可得知目前登入系统的用户有哪些人, 以及他们正在执行的程序. 单独执行w 命令会显示所有的用户, 您也可指定用户名称 ...
- ActiveMQ (二) 常用配置简介
ActiveMQ的主要配置文件 ActiveMQ的一些常用的属性很多可以在对应的配置文件中进行配置的.比如访问web console的管理端的端口,用户名密码,连接MQ时的用户名和密码,持久化设置,是 ...
- linux系统中,文件的三种特殊权限
背景介绍 在linux系统中,我们熟知有rwx三种权限,对应所有者,同组用户,其他用户三种用户的权限,一共9个位来指定一个文件的权限情况,通过chmod xxx 来更改权限属性,其中xxx是已八进制表 ...
- [Android游戏开发]游戏框架的搭建
通常情况下,游戏开发的基本框架中,一般包括以下模块: 窗口管理(Window management):该模块负责在Android平台上创建.运行.暂停.恢复游戏界面等功能. 输入模块(Input):该 ...