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