[BZOJ1066]蜥蜴 做题笔记
2016-03-28 21:33
357 查看
·· / ·– ·· ·-·· ·-·· / ·–· · ·-· ··· ·· ··· - / ··- -· - ·· ·-·· / ·· / ·– ·· -·
题目来源:http://www.lydsy.com/JudgeOnline/problem.php?id=1066
做这题的时候被自己打的模板坑了,查了好久好久都没查出错。。。以后做题也不能过分信任某一段代码而不去查它的错了。
恩,这题的背景总让人想起科学的上网。。
这题的距离是指欧几里得距离,就是sqrt( (x1-x2)^2+(y1-y2)^2 ),我之前竟然没有见过,按照上下左右还有对角线去遍历,结果显而易见。。
题目来源:http://www.lydsy.com/JudgeOnline/problem.php?id=1066
做这题的时候被自己打的模板坑了,查了好久好久都没查出错。。。以后做题也不能过分信任某一段代码而不去查它的错了。
恩,这题的背景总让人想起科学的上网。。
这题的距离是指欧几里得距离,就是sqrt( (x1-x2)^2+(y1-y2)^2 ),我之前竟然没有见过,按照上下左右还有对角线去遍历,结果显而易见。。
#include <cstdio> #include <cstring> #include <algorithm> #include <queue> using namespace std; const int N=1000,M=100000,inf=0x3fffffff; int head ,ver[M<<1],e[M<<1],nxt[M<<1]; int cnt=0,tot=1,frog=0,r,c,ans=0,s,t,dis; int d ,map[100][100],pos[100][100]; void add (int u,int v,int w) { ver[++tot]=v;e[tot]=w;nxt[tot]=head[u];head[u]=tot; ver[++tot]=u;e[tot]=0;nxt[tot]=head[v];head[v]=tot; } bool bfs () { queue <int> q; memset(d,0,sizeof(d)); q.push(s); d[s]=1; while (!q.empty()) { int x=q.front(); q.pop(); for (int i=head[x];i;i=nxt[i]) if (e[i]&&!d[ver[i]]) {//这里之前打成&了 q.push(ver[i]); d[ver[i]]=d[x]+1; if (ver[i]==t) return 1; } } return 0; } int dinic (int x,int f) { int rest=f; if (x==t) return f; for (int i=head[x];i&&rest;i=nxt[i]) if (e[i]&&d[ver[i]]==d[x]+1) { int now=dinic(ver[i],min(e[i],rest)); if (!now) d[ver[i]]=0; e[i]-=now; e[i^1]+=now; rest-=now; } return f-rest; } bool check (int i,int j,int u,int v) { if ( (j-v)*(j-v)+(i-u)*(i-u)<=(dis*dis) && map[i][j] &&map[u][v] && ((i!=u)||(j!=v))) return 1; return 0; } void build () { char ch; cnt=r*c;s=0,t=cnt*2+1; for (int i=1;i<=r;i++) for (int j=1;j<=c;j++) if (map[i][j]&&(i-1<dis ||r-i<dis ||j-1<dis ||c-j<dis )) add(cnt+pos[i][j],t,inf); for (int i=1;i<=r;i++) for (int j=1;j<=c;j++) if (map[i][j]) add(pos[i][j],cnt+pos[i][j],map[i][j]); for (int i=1;i<=r;i++) { for (int j=1;j<=c;j++) { scanf("%c",&ch); if (ch=='.') continue; ++frog; add(s,pos[i][j],1); } scanf("%*c"); } for (int i=1;i<=r;i++) for (int j=1;j<=c;j++) for (int u=i-dis;u<=i+dis;u++) for (int v=j-dis;v<=j+dis;v++) if (check(i,j,u,v)) add(cnt+pos[i][j],pos[u][v],inf); } int main () { char ch; int tmp; scanf("%d%d%d%*c",&r,&c,&dis); for (int i=1;i<=r;i++) { for (int j=1;j<=c;j++) { scanf("%c",&ch); pos[i][j]=++cnt; map[i][j]=ch-48; } scanf("%*c"); } build(); while (bfs()) while (tmp=dinic(s,inf)) ans+=tmp; printf("%d\n",frog-ans); }
相关文章推荐
- OpenStack培训的用户体验
- JAVAEE 框架 2016-3-28
- 协议和代理
- Windows程序设计(第五版)学习:第三章 窗口与消息
- easyui-combobox实现级联查询
- 04-树6 Complete Binary Search Tree (30分)
- 判断是不是胖子
- 【09类和模块】——5:构造函数名称
- CDOJ 1071 秋实大哥下棋
- hdu 5651 xiaoxin juju needs help 逆元 两种求解方式
- 本月有几天
- uestc1134男神的约会【状压dp】
- File 类
- [置顶] 未知图片宽高水平垂直居中
- D17
- iOS文件操作学习3-28
- 求四个数的最大公约数
- ehcache memcache redis三大缓存男高音
- AndroidStudio项目提交(更新)到github最详细步骤
- 第五周项目1 三角形类练习(4)