内容目录
在C++中 double会以牺牲最小数为代价换取高位
另外请看好题目是求整数部分还是四舍五入
#include<cstdio> #include<cstring> #include<cstdlib> #include<cmath> #include<cctype> #include<iostream> #include<functional> #include<algorithm> #include<string> using namespace std; #define MAXN (1000+10) int a[MAXN][MAXN],n; int main() { long double ans=0.0; scanf("%d",&n); long long all=0; for (int i=1;i<=n;i++) { for (int j=1;j<=n;j++) all+=((long long)n-i+1)*((long long)n-j+1); } for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) { scanf("%d",&a[i][j]); ans+=(long double)(a[i][j])*(long double)(n-i+1)*(long double)(n-j+1)*(long double)(i*j); // cout<<ans<<' '; } cout.setf(ios::fixed); cout.precision(0); cout<<trunc(ans/(long double)(all))<<endl; return 0; }