UVA 12529 Fix the Pond
来源:互联网 发布:linux 修改帐号密码 编辑:程序博客网 时间:2024/05/17 08:24
转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents by---cxlove
这是2012年lartin america 的题目。
巨坑啊,练习的时候yobobobo一度认为正解是流。
其实 是这样的。。。
最终要使得整个图是连通的。
先数一下有几个连通子块。
总有一种方案调整档板,可以使得两个连通子块连通。
所以大概就是连通块的个数减一吧。
但是这题给的数据太蘑菇了。。。。
真没啥好说的题。。。。
#include<iostream>#include<cstdio>#include<cmath>#include<queue>#include<cstring>#define mp(a,b) make_pair(a,b)#pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std;int n;char str[1000][1000];bool flag[1000][1000];int way[4][2]={0,1,0,-1,1,0,-1,0};void bfs(int x,int y){ queue<pair<int,int> >que; flag[x][y]=1; que.push(mp(x,y)); while(!que.empty()){ pair<int,int>u=que.front(),v; que.pop(); for(int i=0;i<4;i++){ x=u.first;y=u.second; int xx=u.first+way[i][0]; int yy=u.second+way[i][1]; if(xx<0||yy<0||xx>=2*n||yy>=2*n+1||flag[xx][yy]) continue; int x1=min(x,xx),x2=max(x,xx); int y1=min(y,yy),y2=max(y,yy); //左右移动 if(i<2){ if(y1&1){ if(x==0||x==2*n-1||str[x%2==0?x-1:x][(y-1)/2]=='H'){ que.push(mp(xx,yy)); flag[xx][yy]=1; } } else{ if(y2==2*n||str[x&1?(x-1):x][y2/2]=='H'){ que.push(mp(xx,yy)); flag[xx][yy]=1; } } } else{ if(x1&1){ if(y==0||str[(x1%2==0?(x1-1):x1)][(y-1)/2]=='V'){ que.push(mp(xx,yy)); flag[xx][yy]=1; } } else{ if(y==2*n||str[x1][y2/2]=='V') { que.push(mp(xx,yy)); flag[xx][yy]=1; } } } } }}int main(){ while(scanf("%d",&n)!=EOF){ int cnt=0; memset(flag,false,sizeof(flag)); for(int i=0;i<2*n-1;i++) scanf("%s",str[i]); for(int i=0;i<2*n;i++){ for(int j=0;j<2*n+1;j++){ if(flag[i][j]) continue; cnt++; bfs(i,j); } } printf("%d\n",cnt-1); } return 0;}
- UVA 12529 Fix the Pond
- UVA 12529 Fix the Pond 题解
- Fix the Pond 北师8.7
- Pond
- Fix the Problem with MergeList
- LZ Fix the first bug
- Fix Your Site With the Right DOCTYPE!
- Fix Your Site With the Right DOCTYPE!
- The best way to fix a bug
- fix the Ubuntu GPG Error BADSIG
- Div Popup fix the page content height
- Fix the computers(解题报告)
- ubuntu fix "the package system is broken"
- Fix Your Site With the Right DOCTYPE!
- how to fix the frame size?
- FIX
- poj3271 Lilypad Pond bfs
- Warning: The VM will try to fix the stack guard now.It's highly recommended that you fix the library
- 输入一个整数数组,调整数组中数字的顺序,使得所有奇数位于数组的前半部分,所有偶数位于数组的后半部分
- gcc 源码分析-序
- Java通用程序设计与集合方法总结
- 浅谈程序员的职业规划
- 解决win7右下角音量控制图标、电池图标消失的脚本
- UVA 12529 Fix the Pond
- ZF 多模块配置
- 8.密码发生器
- 题目1084: 二叉树遍历
- 线程池ThreadPoolExecutor使用简介 (3)
- 9.夺冠概率
- 图片放大镜
- freemarker模板解析----典型的访问者模式和解释器模式
- PHP中COOKIE的详解