给一个图,寻找十字交叉的个数,十字交叉应为两个大于3的奇数交叉与正中央。图的大小很小。

使用DFS搜八连块,之后按照规则筛选出符合条件的交叉。

我的筛选规则有点蠢,先将点排序,再通过三段for循环判断。

 #include <algorithm>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map> using namespace std; struct Node{
int x;
int y;
bool operator < (const struct Node &b) const
{
if(x <= b.x)
{
if(x == b.x) return y <= b.y;
else return true;
}
return false;
}
}cross[]; int N,M,T;
char G[];
int vis[];
int dx[] = {,-,,},dy[] = {,,,-};
int P; void dfs(int u)
{
vis[u] = true;
cross[P].x = u%N;cross[P].y = u/N;
P++;
for(int i=;i<;i++)
{
int x = u%N + dx[i],y = u/N + dy[i];
if(x >= && x < N && y >= && y < N &&!vis[y*N+x] && G[y*N+x] == '#')
{
dfs(x+y*N);
}
}
} int main()
{
while(scanf("%d ",&N) && N)
{
char s[];
for(int i=;i<N;i++)
{
scanf("%s",s);
for(int j=;j<N;j++)
{
G[i*N+j] = s[j];
}
} memset(vis,,sizeof vis);
int ans = ;
for(int i=;i<N;i++)
{
for(int j=;j<N;j++)
{
if(G[i*N+j] != '#' || vis[i*N+j]) continue;
P = ;
dfs(i*N+j);
// printf("P=%d\n",P);
if(P % == || P < ) continue;
else
{
//printf("check\n");
sort(cross,cross+P);
/*
for(int i=0;i<P;i++)
{
printf("%d:(%d,%d)\n",i,cross[i].x,cross[i].y);
}
*/
int len = (P+)/,ok = ,step = ;
for(int i=;i<(len-)/;i++)
{
if(cross[i].x != cross[].x+i || cross[i].y != cross[].y) {ok = ;break;}
}
step += (len-)/;
for(int i=step;i < len+step;i++)
{
if(cross[i].y != (cross[step].y+i-step)
|| cross[i].x != cross[step].x
|| cross[step].x != cross[step-].x+
|| cross[step].y != cross[step-].y-(len-)/)
{ok = ;break;}
}
step += len;
for(int i=step;i< step + (len-)/;i++)
{
if(cross[i].x != (cross[step].x+i-step)
|| cross[i].y != cross[step].y
|| cross[step].y != cross[].y)
{ok = ;break;}
}
if(ok) ans++;
} }
}
printf("%d\n",ans);
}
}

HDU4414-DFS的更多相关文章

  1. hdu4414(DFS 找十字架数量)

    Problem Description The Nazca Lines are a series of ancient geoglyphs located in the Nazca Desert in ...

  2. BZOJ 3083: 遥远的国度 [树链剖分 DFS序 LCA]

    3083: 遥远的国度 Time Limit: 10 Sec  Memory Limit: 1280 MBSubmit: 3127  Solved: 795[Submit][Status][Discu ...

  3. BZOJ 1103: [POI2007]大都市meg [DFS序 树状数组]

    1103: [POI2007]大都市meg Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2221  Solved: 1179[Submit][Sta ...

  4. BZOJ 4196: [Noi2015]软件包管理器 [树链剖分 DFS序]

    4196: [Noi2015]软件包管理器 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 1352  Solved: 780[Submit][Stat ...

  5. 图的遍历(搜索)算法(深度优先算法DFS和广度优先算法BFS)

    图的遍历的定义: 从图的某个顶点出发访问遍图中所有顶点,且每个顶点仅被访问一次.(连通图与非连通图) 深度优先遍历(DFS): 1.访问指定的起始顶点: 2.若当前访问的顶点的邻接顶点有未被访问的,则 ...

  6. BZOJ 2434: [Noi2011]阿狸的打字机 [AC自动机 Fail树 树状数组 DFS序]

    2434: [Noi2011]阿狸的打字机 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 2545  Solved: 1419[Submit][Sta ...

  7. POJ_2386 Lake Counting (dfs 错了一个负号找了一上午)

    来之不易的2017第一发ac http://poj.org/problem?id=2386 Lake Counting Time Limit: 1000MS   Memory Limit: 65536 ...

  8. 深度优先搜索(DFS)

    [算法入门] 郭志伟@SYSU:raphealguo(at)qq.com 2012/05/12 1.前言 深度优先搜索(缩写DFS)有点类似广度优先搜索,也是对一个连通图进行遍历的算法.它的思想是从一 ...

  9. 【BZOJ-3779】重组病毒 LinkCutTree + 线段树 + DFS序

    3779: 重组病毒 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 224  Solved: 95[Submit][Status][Discuss] ...

  10. 【BZOJ-1146】网络管理Network DFS序 + 带修主席树

    1146: [CTSC2008]网络管理Network Time Limit: 50 Sec  Memory Limit: 162 MBSubmit: 3495  Solved: 1032[Submi ...

随机推荐

  1. 关于Http 传输二维json

    传输一维的好说 public static String doPost(String url) { String result = new String(); OutputStream out = n ...

  2. HTML5-应用程序缓存(Application Cache)

    一.什么是应用程序缓存? HTML5 引入了应用程序缓存(Application Cache),这意味着 web 应用可进行缓存,并可在没有因特网连接时进行访问. 二.优势 离线浏览 - 用户可在应用 ...

  3. Ionic2 App Import BrowserAnimationsModule or NoopAnimationsModule问题

    在开发app的过程中遇见了动画相关方面的问题,具体如下: 解决方法是:在app.module.ts模块中引入BrowserAnimationsModule import { BrowserAnimat ...

  4. Luogu P2568 GCD

    我们首先发现这样肯定是做不了的,所以我们枚举为\(gcd(x,y)=d\)的\(d\) 然后考虑以下的性质: \(gcd(x,y)=1 \Leftrightarrow gcd(px,py)=p(p为素 ...

  5. 使用xshell连接服务器,数字键盘无法使用解决办法

    打开会话管理器,选中需要设置的服务器连接,右键->属性 选中 终端->VT模式->初始数字键盘模式->设为普通 保存,重新连接即可.

  6. C# 读取Json配置文件

    今天需要用到读取Json配置文件的helper   结果竟然没找到合适的    微软自己有一个 不过不支持.Net fw 4.0 于是自己在NewTonSoft.Json的基础上  加了点小小的封装  ...

  7. 基于DDD的.NET开发框架ABP实例,多租户 (Saas)应用程序,采用.NET MVC, Angularjs, EntityFramework-介绍

    介绍 基于ABPZERO的多租户 (Saas)应用程序,采用ASP.NET MVC, Angularjs-介绍 ASP.NET Boilerplate作为应用程序框架. ASP.NET MVC和ASP ...

  8. Fedora 19关闭防火墙

    关闭防火墙systemctl stop firewalld.service 关闭开机启动防火墙systemctl disable firewalld.service

  9. sigar开发(java)

    下载sigar,地址:https://yunpan.cn/cBEWbEfdAm98f (提取码:f765) 可以收集的信息 CPU信息:包括基本信息(vendor.model.mhz.cacheSiz ...

  10. HTML 5 拖放

    拖放(Drag 和 drop)是 HTML5 标准的组成部分. 拖放 拖放是一种常见的特性,即抓取对象以后拖到另一个位置. 在 HTML5 中,拖放是标准的一部分,任何元素都能够拖放. 拖放事件 1. ...