#include<bits/stdc++.h>
using namespace std; const int maxn = ;
char str[maxn][maxn];
int cntx[maxn], cnty[maxn],x[maxn],y[maxn]; int main(void){
int T,n,m;scanf("%d",&T);
while(T --){
scanf("%d%d",&n,&m);
int tot = ;
memset(cntx, , sizeof(cntx));
memset(cnty, , sizeof(cnty));
memset(x, -, sizeof(x));
memset(y, -, sizeof(y));
for(int i = ; i < n; i ++){
scanf("%s", str[i]);
for(int j = ; j < m; j ++){
if(str[i][j] == '#'){
cntx[i] ++;cnty[j] ++;
tot ++;
}else{
x[i] = j;y[j] = i;
}
}
}
long long ans = ;
for(int i = ; i < n; i ++)
for(int j = i + ; j < n; j ++)
ans += (long long)(j - i) * cntx[i] * cntx[j] * ;
for(int i = ; i < m; i ++)
for(int j = i + ; j < m; j ++)
ans += (long long)(j - i) * cnty[i] * cnty[j] * ; int cnt = ;
for(int i = ; i < n; i ++){
if(x[i] == -) cnt = ;
else if(i == || x[i] <= x[i - ]) cnt = x[i];
else cnt += x[i];
if(x[i] != -)
ans += 4LL * cnt * (m - x[i] - );
}
cnt = ;
for(int i = ; i < n; i ++){
if((i == )||(x[i] > x[i - ])||(x[i] == -)) cnt = m - x[i] - ;
else cnt += m - x[i] - ;
if(x[i] >= )
ans += 4LL * (cnt - m + x[i] + ) * (x[i]>?x[i]:);
} cnt = ;
for(int i = ; i < m; i ++){
if(y[i] == -) cnt = ;
else if(i == || y[i] <= y[i - ]) cnt = y[i];
else cnt += y[i]; ans += 4LL * cnt * (n - y[i] - );
}
cnt = ;
for(int i = ; i < m; i ++){
if((i == )||(y[i] > y[i - ])||(y[i] == -)) cnt = n - y[i] - ;
else cnt += n - y[i] - ;
if(y[i] >= )
ans += 4LL * (cnt - n + y[i] + ) * (y[i]>?y[i]:);
} printf("%.4lf\n",(double)ans/tot/tot);
}
return ;
}

最新文章

  1. MongoDB学习笔记~官方驱动嵌套数组对象的更新
  2. [Android] Web Console: Uncaught TypeError: Object [object Object] has no method &#39;xxx&#39;
  3. fiddler插件开发step by step 1
  4. ios 复制黏贴板的使用
  5. jQuery Validation让验证变得如此easy(一)
  6. c++ 类名和enum时重复时要在类名前加class::
  7. OpenGL网络资源
  8. Ubuntu安装pycharm
  9. [PKU2389]Bull Math (大数运算)
  10. bzoj 3675: [Apio2014]序列分割
  11. C# 13行代码带你模拟登录QQ空间
  12. python 写入Excel
  13. 处理用千牛导出淘宝数据,供Logstash到Elasticsearch使用。(NodeJS)
  14. loadrunner请求json数据参数化问题
  15. 存在重复元素(python3)
  16. 使用.NET Core与Google Optimization Tools实现员工排班计划Scheduling
  17. Android性能检测工具——traceview
  18. Http协议中常用字段总结(不定时完善中)
  19. SQL SERVER 2014--内存表实现秒杀场景
  20. [转]RESTful API 设计指南

热门文章

  1. 20165336 2017-2018-2 《Java程序设计》第3周学习总结
  2. Python摸爬滚打之day04----基本数据类型(列表,元组)
  3. Why does the memory usage increase when I redeploy a web application?
  4. wps去广告
  5. 2018天猫双11各类目品牌成交额top10排行榜
  6. MySQL5.7配置基于GTID的复制
  7. String扩展 让你在PadLeft和PadRight时不再受单双字节问题困扰
  8. struct模块
  9. ORM之视图层
  10. Scala集合(二)