鱼C论坛

 找回密码
 立即注册
查看: 1911|回复: 1

[已解决]求助

[复制链接]
发表于 2022-8-28 18:29:57 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x

如图
屏幕截图 2022-08-28 182907.png

最佳答案
2022-8-28 19:40:41
本帖最后由 柿子饼同学 于 2022-8-28 20:23 编辑

这个数据量很小了, 范围又是确定的, 直接暴力都可以, 这个是 O(n^2), 暴力好像就常数大一点
建议自己先思考再来问
不过用前缀和优化了一下下
还有, 下次测试样例打字上来吧
  1. #include <bits/stdc++.h>
  2. using namespace std;

  3. long long sum[12][12];
  4. int mp[12][12];
  5. int n;
  6. long long maxpart = LONG_LONG_MIN;
  7. double ans;

  8. int main(){
  9.     ios::sync_with_stdio(0);
  10.     cin.tie(0); cout.tie(0);
  11.    
  12.     cin >> n;
  13.     for(int i = 1; i <= n; i++){
  14.         for(int j = 1; j <= n; j++){
  15.             cin >> mp[i][j];
  16.             sum[i][j] = sum[i-1][j] + mp[i][j]; // 列的前缀和
  17.         }
  18.     }

  19.     for(int j = 1; j <= n-1; j++){
  20.         for(int i = 1; i <= n-1; i++){
  21.             maxpart = max(maxpart, sum[i+1][j]-sum[i-1][j] + sum[i+1][j+1]-sum[i-1][j+1]);
  22.         }
  23.     }

  24.     ans = (double)maxpart / 4;

  25.     cout << fixed << setprecision(2) << ans << endl;
  26.    
  27.     return 0;
  28. }

  29. /* 你的样例
  30. 3
  31. 1 2 3
  32. 2 3 4
  33. 3 4 5
  34. */
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2022-8-28 19:40:41 | 显示全部楼层    本楼为最佳答案   
本帖最后由 柿子饼同学 于 2022-8-28 20:23 编辑

这个数据量很小了, 范围又是确定的, 直接暴力都可以, 这个是 O(n^2), 暴力好像就常数大一点
建议自己先思考再来问
不过用前缀和优化了一下下
还有, 下次测试样例打字上来吧
  1. #include <bits/stdc++.h>
  2. using namespace std;

  3. long long sum[12][12];
  4. int mp[12][12];
  5. int n;
  6. long long maxpart = LONG_LONG_MIN;
  7. double ans;

  8. int main(){
  9.     ios::sync_with_stdio(0);
  10.     cin.tie(0); cout.tie(0);
  11.    
  12.     cin >> n;
  13.     for(int i = 1; i <= n; i++){
  14.         for(int j = 1; j <= n; j++){
  15.             cin >> mp[i][j];
  16.             sum[i][j] = sum[i-1][j] + mp[i][j]; // 列的前缀和
  17.         }
  18.     }

  19.     for(int j = 1; j <= n-1; j++){
  20.         for(int i = 1; i <= n-1; i++){
  21.             maxpart = max(maxpart, sum[i+1][j]-sum[i-1][j] + sum[i+1][j+1]-sum[i-1][j+1]);
  22.         }
  23.     }

  24.     ans = (double)maxpart / 4;

  25.     cout << fixed << setprecision(2) << ans << endl;
  26.    
  27.     return 0;
  28. }

  29. /* 你的样例
  30. 3
  31. 1 2 3
  32. 2 3 4
  33. 3 4 5
  34. */
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-23 21:14

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表