poj 2375
来源:互联网 发布:国内的人工智能龙头股 编辑:程序博客网 时间:2024/06/05 07:39
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>#include <cmath>#define N 510using namespace std;struct Node{ int v,next;}e[N*N*4];int head[N*N],e_num,num,od[N*N],id[N*N];int map[N][N],temp_map[N][N];int dir[][2]={0,1,1,0};bool vis[N*N];int low[N*N],stack[N*N],s[N*N],scc_num,top,s_n,p[N*N];void add_edge( int u, int v){ e[e_num].v=v; e[e_num].next=head[u]; head[u]=e_num++;}void get_map(int m, int n ){ memset(head,-1,sizeof(head)); e_num=0; for( int i=1; i<=m; i++ ) { for( int j=1; j<=n; j++ ) { for( int k=0; k<2; k++ ) { int x=i+dir[k][0]; int y=j+dir[k][1]; if(x>=1&&x<=m&&y>=1&&y<=n) { if(map[x][y]<=map[i][j]) add_edge(temp_map[i][j],temp_map[x][y]); if(map[x][y]>=map[i][j]) add_edge(temp_map[x][y],temp_map[i][j]); } } } }}void dfs( int u, int dfs_num, int &scc_num){ low[u]=++dfs_num; s[++s_n]=u; stack[++top]=u; for( int i=head[u]; i!=-1; i=e[i].next ) { if(!low[e[i].v]) dfs(e[i].v,dfs_num,scc_num); else if(p[e[i].v]==0) { while(low[stack[top]]>low[e[i].v])--top; } } if( stack[top]==u ) { top--; scc_num++; do { p[s[s_n]]=scc_num; }while(s[s_n--]!=u); } return ;}void work(){ int scc_num=0,dfs_num=0; memset(p,0,sizeof(p)); memset(low,0,sizeof(low)); s_n=top=0; for( int i=1; i<=num; i++ ) { if(!low[i])dfs(i,dfs_num,scc_num); } memset(od,0,sizeof(od)); memset(id,0,sizeof(id)); for( int u=1;u<=num; u++ ) { for( int i=head[u];i!=-1;i=e[i].next) { int v=e[i].v; if(p[u]!=p[v])od[p[u]]++,id[p[v]]++; } } int i_num=0,o_num=0; for( int i=1; i<=scc_num; i++) { if(!od[i])o_num++; if(!id[i])i_num++; } if(scc_num==1)printf("0\n"); else printf("%d\n",max(i_num,o_num));}int main(){ // freopen("in.txt","r",stdin); int W,L; while( ~scanf("%d%d",&W,&L)) { num=0; for( int i=1;i<=L; i++ ) for( int j=1;j<=W; j++ ) { scanf("%d",&map[i][j]); temp_map[i][j]=++num; } get_map(L,W); work(); } return 0;}
- poj 2375
- poj 2375
- POJ 2375
- POJ 2375 解题报告
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- poj
- POJ
- POJ
- POJ
- POJ
- POJ
- android进程间通信:使用AIDL
- 学习Gtkmm系列之七
- VFS与Ext2文件系统------《深入Linux内核架构》笔记
- jquery中的属性过滤选择器
- PreCreateWindow
- poj 2375
- 开源文化
- 美妙的模电2013/4/18
- IOS开发之深拷贝与浅拷贝(转自博客园)
- hdu 3572最大流
- 404错误是什么意思?为什么是404?
- jquery中的子元素过滤选择器
- 求割点
- Time