SSL2787 2017年10月24日提高组 一个不成熟的想法(dfs)
来源:互联网 发布:触景无限 知乎 编辑:程序博客网 时间:2024/04/29 15:18
2017年10月24日提高组 一个不成熟的想法
Description
Ymw因为十分厉害,刷题已经不能满足他了,他想去写一个小程序来实现一些功能,现在有一个2N*2M的矩形水池,被一些宽度不计的隔板所隔开,每个2*2的小矩形中都有两块弧形隔板,且只有可能是这两种图案中的一种:
现在你看到了ymw的水池的样子,ymw有Q个问题,每次想知道如果在(x,y)上倒了一同染料,则最终可以扩散多大的面积?
Input
Output
分析:显然可得染料在每个矩形中的扩散只有四种情况,即从4个顶点开始扩散,这样两种图案就有8种,dfs一下就好啦。
代码
#include <cstdio>#include <cstring>#include <string>#include <iostream>#define maxn 500#define pi 3.141592653589793using namespace std;int a[maxn][maxn],n,m;double ans;bool f[maxn][maxn],v[maxn][maxn][5];bool check(int x,int y,int tmp){ if (x<0||x>n-1||y<0||y>m-1) return false; if (a[x][y]==0) { if (tmp==1||tmp==4) if (v[x][y][tmp]) return false; if (tmp==2||tmp==3) if (v[x][y][2]||v[x][y][3]) return false; } else { if (tmp==2||tmp==3) if (v[x][y][tmp]) return false; if (tmp==1||tmp==4) if (v[x][y][1]||v[x][y][4]) return false; } return true;}void dfs(int x,int y,int tmp){ if (!check(x,y,tmp)) return; v[x][y][tmp]=true; if (a[x][y]==0) { if (tmp==1) { ans+=pi/4; return; } if (tmp==2) { ans+=4-pi/2; dfs(x,y-1,4); dfs(x+1,y,1); dfs(x+1,y-1,2); } if (tmp==3) { ans+=4-pi/2; dfs(x-1,y,4); dfs(x,y+1,1); dfs(x-1,y+1,3); } if (tmp==4) { ans+=pi/4; return; } } else { if (tmp==1) { ans+=4-pi/2; dfs(x+1,y,2); dfs(x,y+1,3); dfs(x+1,y+1,1); } if (tmp==2) { ans+=pi/4; return; } if (tmp==3) { ans+=pi/4; return; } if (tmp==4) { ans+=4-pi/2; dfs(x,y-1,2); dfs(x-1,y,3); dfs(x-1,y-1,4); } }}int main(){ scanf("%d%d",&n,&m); for (int ii=0;ii<=n-1;ii++) for (int jj=0;jj<=m-1;jj++) { char ch; cin>>ch; a[ii][jj]=ch-'0'; int i=ii; int j=jj; if (ch=='0') { f[i*2][j*2+1]=true; f[i*2+1][j*2]=true; f[(i+1)*2][j*2+1]=true; f[i*2+1][(j+1)*2]=true; } else { f[i*2][j*2+1]=true; f[i*2+1][(j+1)*2]=true; f[i*2+1][j*2]=true; f[(i+1)*2][j*2+1]=true; } } int q; scanf("%d",&q); for (int i=1;i<=q;i++) { int x,y; scanf("%d%d",&x,&y); memset(v,false,sizeof(v)); if (f[x][y]) printf("0.0000\n"); else { if (x%2==1&&y%2==1) { x/=2; y/=2; if (a[x][y]==1) { ans=4-pi/2; v[x][y][1]=true; dfs(x-1,y-1,4); dfs(x,y-1,2); dfs(x-1,y,3); dfs(x+1,y,2); dfs(x,y+1,3); dfs(x+1,y+1,1); } else { ans=4-pi/2; v[x][y][2]=true; dfs(x-1,y,4); dfs(x,y+1,1); dfs(x-1,y+1,3); dfs(x+1,y,1); dfs(x+1,y-1,2); dfs(x,y-1,4); } } else { x/=2; y/=2; dfs(x,y,1); dfs(x-1,y,3); dfs(x-1,y-1,4); dfs(x,y-1,2); } printf("%.4f\n",ans); ans=0; } }}
阅读全文
0 0
- SSL2787 2017年10月24日提高组 一个不成熟的想法(dfs)
- 【SSLGZ 2788】2017年10月24日提高组 想法的升级
- SSL2682 2017年8月12日提高组T1 YMW的杯子(dfs)
- SSL2776 2017年10月19日提高组 整除(容斥+dfs)
- SSL2675 2017年8月9日提高组T3 难题(dfs)
- SSL2703 2017年8月16日提高组T2 疾病(dfs)
- SSL2836 2017年11月4日提高组T2 序列(迭代dfs)
- SSL2668 2017年8月7日提高组T1 根(dfs)
- SSL2669 2017年8月7日提高组T1 选数(dfs)
- SSL2772 2017年10月17日提高组 被关押的ymw(prim)
- SSL2777 2017年10月21日提高组 偷懒的西西(二分+dp)
- SSL2790 2017年10月25日提高组T2 次方的运算(math)
- 2017年8月10日提高组T1 数学
- 2017年8月10日提高组T1 数学
- 2017年8月10日提高组T1 数学
- 2017年10月6日提高组T2 挖矿
- 2017年10月6日提高组T2 挖矿
- 2017年10月7日提高组T1 染色
- leetcode---remove-duplicates-from-sorted-list---链表
- java压缩字符串
- LaTex(PART XIV)\renewcommand重新定义原有命令
- ii
- SQLite 的简单使用(以Navicat为例)
- SSL2787 2017年10月24日提高组 一个不成熟的想法(dfs)
- 网络状态判断
- oracle的存储过程
- 数据结构java部分
- CXF异常:Error creating bean with name 'org.apache.cxf.jaxws.EndpointImpl---86262394
- VS 2015 + Qt 5.8 环境配置
- 基础练习 特殊回文数
- 规范 6.2 不要使用危险的许可与目标组合 说明: 有些许可和目标的组合会导致权限过大, 而这些权限本不应该被赋予。另外有些权限 必须只赋予给特定的代码。 1. 不要将AllPermission许可赋
- android 底部快速button