CodeForces 723D Lakes in Berland DFS
来源:互联网 发布:调音软件哪个好 编辑:程序博客网 时间:2024/05/29 07:37
#include<bits/stdc++.h>using namespace std;const int MAX=55;const int Dx[4]={0,-1,1,0};const int Dy[4]={1,0,0,-1};int N,M,K,Mark[MAX][MAX],Hash[MAX*MAX],Cnt=0,Ans=0;vector<pair<int,int> > V;set<int> S;char G[MAX][MAX];void dfs(int x,int y){ if (x<0||x>N-1||y<0||y>M-1||G[x][y]!='.'||Mark[x][y]!=-1) return; Mark[x][y]=Cnt; Hash[Cnt]+=1; for (int i=0;i<4;i++) dfs(x+Dx[i],y+Dy[i]);}void init(int x,int y){ if (x<0||x>N-1||y<0||y>M-1||G[x][y]!='.') return; G[x][y]='x'; for (int i=0;i<4;i++) init(x+Dx[i],y+Dy[i]);}int main(){ memset(Mark,-1,sizeof(Mark)); memset(Hash,0,sizeof(Hash)); cin>>N>>M>>K; for (int i=0;i<N;i++) cin>>G[i]; for (int i=0;i<N;i++) { init(i,0); init(i,M-1); } for (int j=0;j<M;j++) { init(0,j); init(N-1,j); } for (int i=0;i<N;i++) for (int j=0;j<M;j++) if (G[i][j]=='.'&&Mark[i][j]==-1) { dfs(i,j); V.push_back(make_pair(Hash[Cnt],Cnt)); Cnt+=1; } sort(V.begin(),V.end()); for (int i=0,j=V.size()-K;i<j;i++) { Ans+=V[i].first; S.insert(V[i].second); } cout<<Ans<<endl; for (int i=0;i<N;i++) { for (int j=0;j<M;j++) if (Mark[i][j]!=-1&&S.find(Mark[i][j])!=S.end()) cout<<'*'; else if (G[i][j]=='x') cout<<'.'; else cout<<G[i][j]; cout<<endl; } return 0;}
0 0
- codeforces 723D. Lakes in Berland [DFS]【】
- CodeForces 723D Lakes in Berland DFS
- CodeForces 723D-Lakes in Berland(BFS DFS)
- Codeforces-723D- Lakes in Berland(DFS)
- 【29.70%】【codeforces 723D】Lakes in Berland
- codeforces 723D Lakes in Berland
- Codeforces 723D - Lakes in Berland
- codeforces 723 D. Lakes in Berland
- Codeforces 723D Lakes in Berland
- D.Lakes in Berland(DFS)
- [codeforces] D. Lakes in Berland [dfs and similar]
- codeforces#375(div.2)723D - Lakes in Berland dfs+bfs
- codeforce 723d Lakes in Berland(暴力DFS)
- D. Lakes in Berland 【dfs+贪心】
- D. Lakes in Berland
- D. Lakes in Berland
- 【Codeforces Round 375 (Div 2) D】【简单dfs】Lakes in Berland
- Codeforces Round #375 (Div. 2) D. Lakes in Berland __ dfs+贪心+小根堆
- chm文档:无法打开提、示无法显示
- java学习日记_69:System类
- bzoj 3751: [NOIP2014]解方程 (数论)
- CSU 1162 Balls in the Boxes 快速幂 水
- 批量操作
- CodeForces 723D Lakes in Berland DFS
- 如何对 Android 应用进行性能分析
- 1-100
- 基于社区医疗系统的spring+mybatis架构设计流程----登录
- 嵌入式系统一面观
- 类的继承与派生
- Microsoft JDBC Driver 4.0 for SQL Server下载及安装使用说明
- 树结构练习——判断给定森林中有多少棵树
- uc/os-II 分析(10)--消息队列