4395: [Usaco2015 dec]Switching on the Lights|暴力
来源:互联网 发布:百度软件管家官方下载 编辑:程序博客网 时间:2024/06/08 14:15
广搜 保证不重复进队
然后多搜几遍直到不能更新答案为止
#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<queue>#include<set>#include<map>#include<vector>#include<algorithm>#include<iostream>#define T 43333using namespace std;int sc(){int i=0; char c=getchar();while(c>'9'||c<'0') c=getchar();while(c>='0'&&c<='9') i=i*10+c-'0',c=getchar();return i;}int Head[T],Nxt[T],Lst[T];int head[T],nxt[T],lst[T];int a[22222],b[11111],c[22222];int id[111][111],q[52222];int n,m,cnt,tot,Tot,ans=1;bool jud(int x){if(!a[x]||b[x]) return 0;return 1;}void insert(int x,int y){lst[++tot]=y;nxt[tot]=head[x];head[x]=tot;}void Add(int x,int y){if(x==0||y==0) return ;Lst[++Tot]=y;Nxt[Tot]=Head[x];Head[x]=Tot;}int main(){n=sc(),m=sc();for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) id[i][j]=++cnt;for(int i=1; i<=m; i++){int x=sc(),y=sc(),s=sc(),e=sc();insert(id[x][y],id[s][e]);}for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) { Add(id[i][j],id[i-1][j]); Add(id[i][j],id[i+1][j]); Add(id[i][j],id[i][j+1]); Add(id[i][j],id[i][j-1]); }int last=0,tot=0;while(1){int l=1,r=2;q[1]=1;a[1]=1; memset(b,0,sizeof(b)); while(l<r) { int x=q[l++]; for(int i=head[x]; i; i=nxt[i]) { if(!a[lst[i]]) ans++; a[lst[i]]=1; } for(int i=Head[x]; i; i=Nxt[i]) if(jud(Lst[i])) { b[Lst[i]]=1; q[r++]=Lst[i]; }}if(ans==last)break;last=ans;}cout << ans;return 0;}
0 0
- 4395: [Usaco2015 dec]Switching on the Lights|暴力
- bzoj4395【Usaco2015 Dec】Switching on the Lights
- BZOJ 4397: [Usaco2015 dec]Breed Counting|暴力
- bzoj4394【Usaco2015 Dec】Bessie
- 【Usaco2015 dec 】Counting Haybales
- [Usaco2015 dec]Max Flow
- bzoj4397【Usaco2015 Dec】Breed Counting
- bzoj4393【Usaco2015 Dec】Fruit Feast
- bzoj4392【Usaco2015 Dec】Counting Haybales
- bzoj4390【Usaco2015 Dec】Max Flow
- 【bzoj4390】[Usaco2015 dec]Max Flow
- bzoj4397: [Usaco2015 dec]Breed Counting
- bzoj4390: [Usaco2015 dec]Max Flow
- bzoj4396【Usaco2015 Dec】High Card Wins
- BZOJ 4390: [Usaco2015 dec]Max Flow|树链剖分
- 【Usaco2015 dec】High Card Low Card
- BZOJ4391: [Usaco2015 dec]High Card Low Card
- bzoj4391[Usaco2015 dec]High Card Low Card
- 负载均衡与集群之nginx+tomcat+memcached
- root、oracle用户执行df -h命令卡住
- Qt调用外部exe并同步显示输出
- JavaScript 模拟类(class)的三种方法
- C语言学习之关键字第七讲
- 4395: [Usaco2015 dec]Switching on the Lights|暴力
- p3p协议实现跨域站点登录
- Activity设置全屏显示的两种方式及系统自带theme属性解析
- The specified child already has a parent. You must call removeView() on the child's parent first.
- 起步,Python+Flask记录
- QWebView linkClicked()信号
- 2016【太原网络营销师】郭文军何为社会化媒体的http理论
- 自定义View中,获取string字符串的宽高
- Android网络开发框架Retrofit(五:实战篇,实现MVP模式进行开发)