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

关键词优化seo谷歌seo和百度seo区别

关键词优化seo,谷歌seo和百度seo区别,南昌营销网站建设,免费博客主题wordpress文章目录 前缀和一维前缀和公式CODE 二维前缀和公式CODE 差分一维差分思路作用CODE 二维差分思路CODE 前缀和 一维前缀和 板子题:https://www.acwing.com/activity/content/problem/content/829/ 公式 S [ i ] a [ i ] S [ i − 1 ] S[i] a[i] S[i - 1] S[i]…

文章目录

  • 前缀和
    • 一维前缀和
      • 公式
      • CODE
    • 二维前缀和
      • 公式
      • CODE
  • 差分
    • 一维差分
      • 思路
      • 作用
      • CODE
    • 二维差分
      • 思路
      • CODE



前缀和

一维前缀和

板子题:https://www.acwing.com/activity/content/problem/content/829/

公式

S [ i ] = a [ i ] + S [ i − 1 ] S[i] = a[i] + S[i - 1] S[i]=a[i]+S[i1]

CODE

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

二维前缀和

板子题:https://www.acwing.com/activity/content/problem/content/830/

公式

S [ i ] [ j ] = S [ i − 1 ] [ j ] + S [ i ] [ j − 1 ] − S [ i − 1 ] [ j − 1 ] + a [ i ] [ j ] S[i][j] = S[i - 1][j] + S[i][j - 1] - S[i - 1][j - 1] + a[i][j] S[i][j]=S[i1][j]+S[i][j1]S[i1][j1]+a[i][j]

CODE

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

差分

一维差分

板子题:https://www.acwing.com/activity/content/problem/content/831/

思路

差分其实是前缀和的逆运算,我们假想有一个数组b[],它的前缀和是数组a[],也就是说:
b [ i ] = a [ i ] − a [ i − 1 ] b[i] = a[i] - a[i - 1] b[i]=a[i]a[i1]

作用

这个b[]数组有什么用呢?
在我们对a[]的元素进行加减操作时,如果采用遍历a[]的方法,时间是 o ( N ) o(N) o(N) 的,但是如果我们用b[]对其优化可以使时间复杂度降到 o ( 1 ) o(1) o(1)

a[] [ i , j ] [i, j] [i,j] 段进行+k操作,我们可以在 b[i] + k并在b[j + 1] - k。当我们对b[]求前缀和时,从i开始的每个元素都会+k,但是我们只要加到a[j]就结束了,所以在a[j + 1]进行归位。

CODE

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

整个差分数组的精髓就在于insert()函数,非常巧妙啊,尤其是在读入阶段对b[]数组进行初始化时的操作,这个操作的意义如下:

解释
来源:https://www.acwing.com/activity/content/code/content/39799/


二维差分

板子题:https://www.acwing.com/activity/content/problem/content/832/

思路

答题思路跟一维差分差不多,借鉴二维前缀和的操作我们可以得到以下公式:
a [ i ] [ j ] = b [ i ] [ j ] − b [ i − 1 ] [ j ] − b [ i ] [ j − 1 ] + b [ i − 1 ] [ j − 1 ] a[i][j] = b[i][j] - b[i - 1][j] - b[i][j - 1] + b[i - 1][j - 1] a[i][j]=b[i][j]b[i1][j]b[i][j1]+b[i1][j1]

那我们插入函数该怎么写呢?
一样的原理:
b [ x 1 ] [ y 1 ] + = c b [ x 2 + 1 ] [ y 1 ] − = c b [ x 1 ] [ y 2 + 1 ] − = c b [ x 2 + 1 ] [ y 2 + 1 ] + = c b[x1][y1] += c\\ b[x2 + 1][y1] -= c\\ b[x1][y2 + 1] -=c\\ b[x2 + 1][y2 + 1] += c b[x1][y1]+=cb[x2+1][y1]=cb[x1][y2+1]=cb[x2+1][y2+1]+=c

CODE

#include <iostream>
#include <cstring>
#include <algorithm>using namespace std;int n, m, q;
const int N = 1010;
int a[N][N], b[N][N];
int x1, y1, x2, y2, c;void insert(int x1, int y1, int x2, int y2, int c){b[x1][y1] += c;b[x2 + 1][y1] -= c;b[x1][y2 + 1] -= c;b[x2 + 1][y2 + 1] += c;
}int main()
{cin >> n >> m >> q;for(int i = 1; i <= n; ++i)for(int j = 1; j <= m; ++j){scanf("%d", &a[i][j]);insert(i, j, i, j, a[i][j]);}while(q--){cin >> x1 >> y1 >> x2 >> y2 >> c;insert(x1, y1, x2, y2, c);}for(int i = 1; i <= n; ++i){for(int j = 1; j <= m; ++j){printf("%d ", b[i][j] += b[i - 1][j] + b[i][j - 1] - b[i - 1][j - 1]);}printf("\n");   }
}
http://www.khdw.cn/news/42813.html

相关文章:

  • 星沙做网站如何搜索网页关键词
  • 在58做网站推广有效果吗网店seo是什么意思
  • 中国农业工程建设协会网站网站宣传和推广的方法有哪些
  • 国内网站建设费用联盟百度seo优化培训
  • 灵犀科技 高端网站建设首页企业网站seo
  • 网站开发要花费多少钱百度关键词价格查询
  • 中国风网站模板下载自己建网站的详细步骤
  • 管理登陆网站开发软件重庆人力资源和社会保障网官网
  • 网站备案检验单如何做网站推广广告
  • hfs网络文件服务器可以做网站沧浪seo网站优化软件
  • 商城网站开发嵌入支付宝竞价排名是什么意思
  • 淘宝式网站建设上海谷歌seo推广公司
  • 知乎有趣的网站市场推广计划书
  • 杭州笕桥网站建设网站推广搜索
  • 算命先生的网站怎么做行业门户网站推广
  • 平面设计的网站有哪些网站模板建站难吗
  • 东莞谢岗网站建设电商关键词一般用哪些工具
  • 公司的网站建设价格排名检测
  • 福建泉州做淘宝的拿货什么网站企业网站优化公司
  • 长沙英文网站建设公司汽车软文广告
  • 想要去国外网站买东西怎么做天津百度seo排名优化软件
  • 宁国做网站的深圳网络营销怎么推广
  • 申请个人网站有什么用三叶草gy5987
  • 网站建设发票几个点推广网站seo
  • 怎么做网站代码什么是百度竞价排名服务
  • 郑州 手机网站制作百度下载app下载安装
  • 网站怎么生成二维码关键词查询网址
  • 重庆渝中区企业网站建设联系电话百度快速提交入口
  • 网站网格中国营销策划第一人
  • 合肥做公司网站seo实战指导