HYSBZ -1218 激光炸弹

博客给出了HYSBZ -1218激光炸弹问题的代码实现。代码通过读入目标价值,计算前缀和,再计算最大前缀和(边长小于r),最终输出结果。使用了C++语言,包含了输入输出、数组操作等内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <cmath>
 4 #include <stdio.h>
 5 #include <cstring>
 6 #include <string>
 7 #include <cstdlib>
 8 #include <queue>
 9 #include <stack>
10 #include <set>
11 #include <vector>
12 #include <map>
13 #include <list>
14 #include <iomanip>
15  #include <fstream>
16 using namespace std;
17 
18 int a[5003][5003];
19 
20 int main()
21 {
22     int n,r,x,y,v,nn,mm; 
23     
24     scanf("%d%d",&n,&r);
25     nn=mm=r;
26     //读入目标价值 
27     for(int i=0;i<n;++i)
28     {
29         scanf("%d%d%d",&x,&y,&v);
30         ++x;
31         ++y;
32         a[x][y]+=v;
33         nn=max(nn,x);
34         mm=max(mm,y);
35     }
36     //计算前缀和 
37     for(int i=1;i<=nn;++i)
38     {
39         for(int j=1;j<=mm;++j)
40         {
41             a[i][j]+=a[i][j-1]+a[i-1][j]-a[i-1][j-1];
42         }
43     }
44     //计算最大前缀和,但是要小于边长r 
45     int ans=0,t;
46      for(int i=r;i<=nn;++i)
47      {
48          for(int j=r;j<=mm;++j)
49          {
50              t=a[i][j]-a[i-r][j]-a[i][j-r]+a[i-r][j-r];
51              ans=max(ans,t);
52          }
53      }
54      printf("%d\n",ans);
55      
56     return 0;
57 }

 

转载于:https://www.cnblogs.com/greenaway07/p/11187841.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值