当前位置: 首页 > news >正文

网站建设客户分析调查问卷重庆网站排名提升

网站建设客户分析调查问卷,重庆网站排名提升,中山网站制作建设,网站制作价一维前缀和 S[i] a[1] a[2] ... a[i] a[l] ... a[r] S[r] - S[l - 1]二维前缀和 S[i, j] 第i行j列格子左上部分所有元素的和 以(x1, y1)为左上角,(x2, y2)为右下角的子矩阵的和为: S[x2, y2] - S[x1 - 1, y2] - S[x2, y1 - 1] S[x1 - 1, y1 - …

一维前缀和

S[i] = a[1] + a[2] + ... a[i]
a[l] + ... + a[r] = S[r] - S[l - 1]

二维前缀和

S[i, j] = 第i行j列格子左上部分所有元素的和
以(x1, y1)为左上角,(x2, y2)为右下角的子矩阵的和为:
S[x2, y2] - S[x1 - 1, y2] - S[x2, y1 - 1] + S[x1 - 1, y1 - 1]

练习题

562. 壁画

#include <iostream>
#include <cstring>
#include <algorithm>using namespace std;const int N = 5e6 + 10;
int n;
int s[N];
char str[N];int main()
{int T;scanf("%d", &T);for (int x = 1; x <= T; x ++ ){scanf("%d", &n);scanf("%s", str + 1);memset(s, 0, sizeof s);for (int i = 1; i <= n; i ++ ) s[i] += s[i - 1] + str[i] - '0';int k = (n - 1) / 2 + 1;int sum = 0;for (int i = k; i <= n; i ++ )sum = max(sum, s[i] - s[i - k]);printf("Case #%d: %d\n", x, sum);}return 0;
}

795. 前缀和

#include <iostream>
#include <cstring>
#include <algorithm>using namespace std;const int N = 1e5 + 10;
int n, m;
int s[N];int main()
{scanf("%d%d", &n, &m);for (int i = 1; i <= n; i ++ ) {scanf("%d", &s[i]);s[i] += s[i - 1];}while (m -- ) {int l, r;scanf("%d%d", &l, &r);printf("%d\n", s[r] - s[l - 1]);}return 0;
}

796. 子矩阵的和

#include <iostream>
#include <algorithm>
#include <cstring>using namespace std;int n, m, q;
const int N = 1010;
int s[N][N];int main()
{scanf("%d%d%d", &n, &m, &q);for (int i = 1; i <= n; i ++ ) for (int j = 1; j <= m; j ++ ) scanf("%d", &s[i][j]);for (int i = 1; i <= n; i ++ ) for (int j = 1; j <= m; j ++ ) s[i][j] += s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1];while(q -- ){int x1, y1, x2, y2;cin >> x1 >> y1 >> x2 >> y2;printf("%d\n", s[x2][y2] - s[x1 - 1][y2] - s[x2][y1 - 1] + s[x1 - 1][y1 - 1]);}return 0;
}

1230. K倍区间

#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>using namespace std;typedef long long LL;
const int N = 100010;int n, k;
LL s[N], cnt[N];int main()
{scanf("%d%d", &n, &k);for (int i = 1; i <= n; i ++ ) {scanf("%d", &s[i]);s[i] += s[i - 1];}// for (int i = 1; i <= n; i ++ ) printf("%d ", s[i]);LL res = 0;cnt[0] ++;for (int i = 1; i <= n; i ++ ) {res += (LL)cnt[s[i] % k];cnt[s[i] % k] ++;}printf("%lld\n", res);return 0;
}

4405. 统计子矩阵

#include <iostream>
#include <cstring>
#include <algorithm>using namespace std;typedef long long LL;
const int N = 510;
int n, m, k;
int s[N][N];int main()
{scanf("%d%d%d", &n, &m, &k);for (int i = 1; i <= n; i ++ ) for (int j = 1; j <= m; j ++ ) {scanf("%d", &s[i][j]);s[i][j] += s[i - 1][j];}LL res = 0;      // 枚举上下边界for (int i = 1; i <= n; i ++ ) for (int j = i; j <= n; j ++ )// 双指针降低一层循环来枚举左右边界for (int l = 1, r = 1, sum = 0; r <= m; r ++ ) {sum += s[j][r] - s[i - 1][r];while (sum > k) {sum -= s[j][l] - s[i - 1][l];l ++;}res += r - l + 1;}printf("%lld\n", res);return 0;
}
http://www.hkea.cn/news/688619/

相关文章:

  • 网站备案哪个部门北京推广
  • 澳环网站设计公司网站建设方案
  • 云南旅行社网站建设网络推广有多少种方法
  • 龙岗做商城网站建设网络营销战略的内容
  • 网站建设网络公整站排名
  • 南昌购物网站制作软文广告成功案例
  • 鞍山找工作哪个网站最靠谱千度搜索引擎
  • 济南做网站互联网公司英文seo推广
  • 给企业做网站的公司品牌整合营销传播
  • 互联网技术应用学什么杭州优化建筑设计
  • 重庆网站建设要点襄阳seo优化排名
  • 哪个网站用织梦做的seo站长工具查询系统
  • 本地wordpress 上传搜索引擎优化简历
  • 个人创业做网站软文营销怎么写
  • wordpress相册点击弹出框金华seo全网营销
  • 郑州手机网站建设搜狗网站收录提交入口
  • 清风网站建设抖音推广方式有哪些
  • 工作室网站开发广东网站seo营销
  • 广州正佳广场攻略深圳债务优化公司
  • 如何自己免费建网站seo网站有哪些
  • 南昌网站建设案例如何制作自己的链接
  • wordpress大流量专业的网站优化公司
  • 做进口零食批发网站百度站长管理平台
  • 网站栏目建设存在的问题关键词简谱
  • 网站备案怎么那么麻烦google chrome 网络浏览器
  • 小米手机做网站服务器nba东西部最新排名
  • 做写字楼用哪个网站更好郑州seo代理外包
  • 做网站 淘宝营销策划思路
  • 网页设计要用到什么软件聊城seo优化
  • 用wordpress做网站百度推广管理