Title \ (100 + 50 + 0 \)
Correct
- (When problems do, prompted by the apparent \ (n \ times m \) in the range of 64-bit integer,) enumeration \ (n \ times m \)
- Just enumeration product contains only 0 or 1, similar to binary, queue creating
Thinking
- Reverse entitled seeking \ (m \) , but enumeration \ (n \ times m \)
\ (DHOJ \ 1403 \) or \ (JZOJ \ 3053 \)
Correct
- 50% Manhattan distance, axes partition
- Paint 100%, in some cases ( Interpretations ) +2 Manhattan distance, axes partition
Thinking
- At first I thought a tree-DP, tune fast one hour discovery algorithms wrong
- 50% think of Manhattan, but did not expect the addition principle of divide and conquer +
- Paint not completely, 100 percent of the ignorant
Code
#include <bits/stdc++.h>
#define ri register int
#define N 1000003
using namespace std;
typedef long long LL;
int n,m,sx,sy;
int a[1003][1003];
int heng[1003],zong[1003];
int dis[N];
LL cnt,ans,tmp1,tmp2,tmpnow;
int main(){
freopen("travel.in","r",stdin);
freopen("travel.out","w",stdout);
scanf("%d%d",&n,&m);
char ch;
for(ri i=1;i<=n;++i){
for(ri j=1;j<=m;++j){
while(ch=getchar(),(ch!='.')&&(ch!='X'));
if(ch=='.'){
a[i][j]=1;
++cnt;
}
else {
heng[i]=j;//每一行每一列都只会有一个X
zong[j]=i;
}
}
}
for(ri i=1;i<n;++i){//对x坐标上的曼哈顿距离之和
tmp1=(heng[i]) ? m-1 : m;
for(ri j=i+1;j<=n;++j){
tmp2=(heng[j]) ? m-1 : m;
ans+=2*tmp1*tmp2*abs(j-i);
}
}
for(ri i=1;i<m;++i){//对y坐标上的曼哈顿距离之和
tmp1=(zong[i]!=0) ? n-1 : n;
for(ri j=i+1;j<=m;++j){
tmp2=(zong[j]!=0) ? n-1 : n;
ans+=2*tmp1*tmp2*abs(j-i);
}
}
for(ri i=1;i<=m;++i){//跑列 ,找到那些需要+2(思考为什么?)的点对(哪些?)
if(!zong[i])continue;
tmpnow=n-zong[i];
ans+=2*2*(n-zong[i])*(zong[i]-1);
int j=i+1;
while(zong[j]&&zong[j]<zong[j-1]&&j<=m){
tmp2=zong[j]-1;
ans+=2*2*tmpnow*tmp2;
++j;
}
j=i-1;
while(zong[j]&&zong[j]<zong[j+1]&&j>=1){
tmp1=zong[j]-1;
ans+=2*2*tmpnow*tmp1;
--j;
}
}
for(ri i=1;i<=n;++i){//跑行
if(!heng[i])continue;
ans+=2*2*(m-heng[i])*(heng[i]-1);
tmpnow=m-heng[i];
int j=i+1;
while(heng[j]&&heng[j]<heng[j-1]&&j<=n){
tmp2=heng[j]-1;
ans+=2*2*tmpnow*tmp2;
++j;
}
j=i-1;
while(heng[j]&&heng[j]<heng[j+1]&&j>=1){
tmp1=heng[j]-1;
ans+=2*2*tmpnow*tmp1;
--j;
}
}
printf("%.4lf\n",(double)ans/cnt/cnt);
return 0;
}
Correct
- Half of this location where the number of possible range
- check: mid ratio greater than or equal to 1, otherwise set to 0, in ascending order corresponding to the number of statistics sections 1, 1 is assigned the back section, the front values 0
Thinking
- Wonderful segment tree
- See the changes format, that this is a data structure that, should think of tree line
- But not the sort Maintenance
- Expect to maintain approximately 01 strings, inaccurate sort, it is not accurate the Check, the Check essence without seeking answers to normal Jieci how much, only the possibility of demand