1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场
来源:互联网 发布:越南古代服饰淘宝 编辑:程序博客网 时间:2024/05/19 13:28
#include<algorithm>#include<iostream>#include<cstring>#include<cstdio>#define inf 0x7fffffffusing namespace std;inline int read(){ int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}struct data{int x,y,v;}a[1000001];int dx[8] = {-1, -1, 0, 1, 1, 1, 0, -1}, dy[8] = {0, 1, 1, 1, 0, -1, -1, -1} ; int n,m,ans,mp[1001][1001];bool mark[1001][1001];void dfs(int x,int y){mark[x][y]=1;for(int i=0;i<8;i++){int nowx=x+dx[i],nowy=y+dy[i];if(nowx>=1&&nowy>=1&&nowx<=n&&nowy<=m&&!mark[nowx][nowy]&&mp[nowx][nowy]<=mp[x][y])dfs(nowx,nowy);}}inline bool cmp(data a,data b){return a.v>b.v;}int main(){n=read();m=read();for(int i=1;i<=n;i++)for(int j=1;j<=m;j++){mp[i][j]=read();a[(i-1)*m+j]=(data){i,j,mp[i][j]};}sort(a+1,a+n*m+1,cmp);for(int i=1;i<=n*m;i++)if(!mark[a[i].x][a[i].y])ans++,dfs(a[i].x,a[i].y);printf("%d",ans);return 0;}
0 0
- 1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场
- BZOJ 1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场
- Bzoj 1619 [Usaco2008 Nov]Guarding the Farm 保卫牧场
- DFS-BZOJ-1619-[Usaco2008 Nov]Guarding the Farm 保卫牧场
- 1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场 搜索
- |BZOJ 1619|搜索|[Usaco2008 Nov]Guarding the Farm 保卫牧场
- bzoj1619[Usaco2008 Nov]Guarding the Farm 保卫牧场
- bzoj1619【Usaco2008 Nov】Guarding the Farm 保卫牧场
- bzoj 1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场(DFS)
- BZOJ 1619 USACO 2008 Nov Guarding the Farm 保卫牧场
- 【bzoj1619】【Usaco2008 Nov】Guarding the Farm (阅读理解+bfs)题解&代码
- [Usaco2008 Open]Crisis on the Farm 牧场危机
- Guarding the Farm
- EOJ 2521 Guarding the Farm
- BZOJ 1605 [Usaco2008 Open]Crisis on the Farm 牧场危机 DP
- 麻烦的DP-BZOJ-1605-[Usaco2008 Open]Crisis on the Farm 牧场危机
- bzoj 1605: [Usaco2008 Open]Crisis on the Farm 牧场危机(DP)
- 题解:cheering up the cows[USACO2008 NOV]
- 简介python,找到了解它的其中一个小窗口
- 【LeetCode with Python】 Binary Tree Level Order Traversal
- php的输出缓存及其相关函数
- Java泛型擦除
- Fle.createNewFile() 和 Fle.createTempFile() 比较和区别
- 1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场
- win7 自定义安装php iis
- 背包问题
- 和为s的两个数字VS和为s的连续整数序列(面试题 41)
- 学习总结十八:Hbase数据库介绍
- PowerManager之UserActivity
- Java递归搜索指定文件夹下的匹配文件
- 温度PID控制
- 新生报到