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

网站建设实训教程软文写作的基本要求

网站建设实训教程,软文写作的基本要求,建网站简易软件,信贷客户精准获客题面翻译 题面描述 FJ 有 NNN 头奶牛,每一头奶牛的品种是根西岛 G 或荷斯坦 H 中的一种。 每一头奶牛都有一个名单,第 iii 头奶牛的名单上记录了从第 iii 头奶牛到第 EiE_iEi​ 头奶牛的所有奶牛。 每一种奶牛都有且仅有一位“领导者”,对…

题面翻译

题面描述

FJ 有 NNN 头奶牛,每一头奶牛的品种是根西岛 G 或荷斯坦 H 中的一种。

每一头奶牛都有一个名单,第 iii 头奶牛的名单上记录了从第 iii 头奶牛到第 EiE_iEi 头奶牛的所有奶牛。

每一种奶牛都有且仅有一位“领导者”,对于某一头牛 iii,如果它能成为“领导者”仅当它满足以下条件的至少一个

  • 其记录的名单上包含它的品种的所有奶牛。

  • 其记录的名单上记录了另一品种奶牛的“领导者”。

请求出有多少对奶牛可能成为两种奶牛的领导者,保证存在至少一种。

数据范围

对于 100%100\%100% 的数据:1≤N≤2×105,i≤Ei≤N1\leq N\leq 2\times 10^5,i\leq E_i\leq N1N2×105,iEiN

题目描述

Farmer John has NNN cows (2≤N≤105)(2 \le N \le 10^5)(2N105). Each cow has a breed that is either Guernsey or Holstein. As is often the case, the cows are standing in a line, numbered 1⋯N1 \cdots N1N in this order.

Over the course of the day, each cow writes down a list of cows. Specifically, cow iii
's list contains the range of cows starting with herself (cow iii) up to and including cow Ei(i≤Ei≤N)E_i(i \le E_i \le N)Ei(iEiN).

FJ has recently discovered that each breed of cow has exactly one distinct leader. FJ does not know who the leaders are, but he knows that each leader must have a list that includes all the cows of their breed, or the other breed’s leader (or both).

Help FJ count the number of pairs of cows that could be leaders. It is guaranteed that there is at least one possible pair.

输入格式

The first line contains NNN.

The second line contains a string of length NNN
, with the ith character denoting the breed of the iii-th cow (G meaning Guernsey and H meaning Holstein). It is guaranteed that there is at least one Guernsey and one Holstein.

The third line contains E1⋯ENE_1 \cdots E_NE1EN.

输出格式

Output the number of possible pairs of leaders.

样例 #1

样例输入 #1

4
GHHG
2 4 3 4

样例输出 #1

1

样例 #2

样例输入 #2

3
GGH
2 3 3

样例输出 #2

2

提示

Explanation for Sample 1

The only valid leader pair is (1,2)(1,2)(1,2). Cow 111’s list contains the other breed’s leader (cow 222). Cow 222’s list contains all cows of her breed (Holstein).

No other pairs are valid. For example, (2,4)(2,4)(2,4)
is invalid since cow 444’s list does not contain the other breed’s leader, and it also does not contain all cows of her breed.

Explanation for Sample 2

There are two valid leader pairs, (1,3)(1,3)(1,3) and (2,3)(2,3)(2,3).

Scoring

  • Inputs 3−53-535: N≤100N \le 100N100
  • Inputs 6−106-10610: N≤3000N \le 3000N3000
  • Inputs 11−1711-171117: N≤2×105N \le 2 \times 10^5N2×105

算法思想

本题核心就是分别求G和H的领导者个数,然后相乘得到最后答案。例如#2测试样例,G的领导者有两个,H的领导者有1个,那么他们的组合就有两对。

对于某一头牛来说,如果它能成为“领导者”仅当它满足以上述两个条件的至少一个。由于第二个条件依赖于第一个条件,因此我们可以先求出满足第一个条件的领导者。

暴力枚举(50分)

朴素做法就是两层循环,第一层循环枚举每一头奶牛iii,第二层循环枚举i到a[i]a[i]a[i],计算其本身品种的奶牛头数,判断其名单上是否记录了它的品种的所有奶牛。如果满足条件,就将第i头奶牛进行标记。

然后再标记第二种情况的领导者,也是两层循环,第一层循环枚举每一头奶牛iii,第二层循环枚举i到a[i]a[i]a[i],判断这之间是否存在另一种奶牛的领导者,如果存在则标记。

最后统计两种奶牛领导者的数量,将其相乘就是最终答案

时间复杂度

时间复杂度为O(n2)O(n^2)O(n2)

代码实现

#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 2e5 + 10;
char s[N];
int a[N], g[N], h[N];
int main()
{int n;cin >> n;cin >> s + 1;int s1 = 0, s2 = 0;for(int i = 1; i <= n; i ++){if(s[i] == 'G') s1 ++;else s2 ++;}for(int i = 1; i <= n; i ++) cin >> a[i];//处理第一种领导者:其记录的名单上包含它的品种的所有奶牛for(int i = 1; i <= n; i ++){int gg = 0, hh = 0;for(int j = i; j <= a[i]; j ++){if(s[j] == 'G') gg ++;else hh ++;}if(s[i] == 'G' && gg == s1) g[i] = 1; //标记为领导者else if(s[i] == 'H' && hh == s2) h[i] = 1; //标记为领导者}//处理第二种领导者:其记录的名单上记录了另一品种奶牛的“领导者”。for(int i = 1; i <= n; i ++){for(int j = i; j <= a[i]; j ++){if(s[i] == 'G' && h[j] == 1){g[i] = 1;break;}else if(s[i] == 'H' && g[j] == 1){h[i] = 1;break;}}}int c1 = 0, c2 = 0;for(int i = 1; i <= n; i ++)if(g[i]) c1 ++;for(int i = 1; i <= n; i ++)if(h[i]) c2 ++;cout << c1 * c2 << endl;
}

前缀和优化(100分)

朴素做法的问题在于使用了两层循环,其实第二层循环可以使用前缀和进行优化,用空间换时间。

  • s1[]前缀和数组,s1[i]表示前i个字符中字符G的个数
  • s2[]前缀和数组,s2[i]表示前i个字符中字符H的个数
  • gs[]前缀和数组,gs[i]表示前i头牛中第一类G品种领导者的数量
  • hs[]前缀和数组,hs[i]表示前i头牛中第一类H品种领导者的数量

时间复杂度

朴素做法的时间复杂度为O(n)O(n)O(n)

代码实现

#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 2e5 + 10;
char s[N];
int e[N], s1[N], s2[N], g[N], h[N], gs[N], hs[N];
int main()
{int n;cin >> n;cin >> s + 1;for(int i = 1; i <= n; i ++) cin >> e[i];//s1[i]前缀和, 表示前i个字符中字符G的个数//s2[i]前缀和, 表示前i个字符中字符H的个数for(int i = 1; i <= n; i ++){s1[i] = s1[i - 1], s2[i] = s2[i - 1];if(s[i] == 'G') s1[i] ++;else s2[i] ++;}//处理第一种领导者:其记录的名单上包含本身的品种的所有奶牛for(int i = 1; i <= n; i ++){//gg表示从i到e[i]位置所有G的个数//hh表示从i到e[i]位置所有H的个数int gg = s1[e[i]] - s1[i - 1], hh = s2[e[i]] - s2[i - 1];//其记录的名单上包含本身的品种的所有奶牛if(s[i] == 'G' && gg == s1[n]) g[i] = 1; //将i位置标记为'G'的领导者else if(s[i] == 'H' && hh == s2[n]) h[i] = 1;//将i位置标记为'H'的领导者}//gs[i]前缀和,表示前i个奶牛中G的第一种领导者个数//hs[i]前缀和,表示前i个奶牛中H的第一种领导者个数for(int i = 1; i <= n; i ++){gs[i] = gs[i - 1], hs[i] = hs[i - 1];if(g[i]) gs[i] ++;if(h[i]) hs[i] ++;}//ga表示G的第一种领导者个数,ha表示H的第一种领导者个数int ga = gs[n], ha = hs[n];//处理第二种领导者:其记录的名单上记录了另一品种奶牛的“领导者”。for(int i = 1; i <= n; i ++){  //其记录的名单上记录了另一品种奶牛的领导者if(s[i] == 'G' && (hs[e[i]] - hs[i - 1]) != 0) ga ++;else if(s[i] == 'H' && (gs[e[i]] - gs[i - 1]) != 0) ha ++;}cout << ga * ha << endl;
}

文章转载自:
http://dinncoleucorrhea.bpmz.cn
http://dinncohustle.bpmz.cn
http://dinncosown.bpmz.cn
http://dinnconocturnal.bpmz.cn
http://dinncooneirocritic.bpmz.cn
http://dinncoeternise.bpmz.cn
http://dinncoautobahn.bpmz.cn
http://dinncocalkin.bpmz.cn
http://dinncomeikle.bpmz.cn
http://dinncoscuzz.bpmz.cn
http://dinncophantasm.bpmz.cn
http://dinncoanaplastic.bpmz.cn
http://dinncolipoidal.bpmz.cn
http://dinncooxycalcium.bpmz.cn
http://dinncoprettyish.bpmz.cn
http://dinncosuit.bpmz.cn
http://dinncopostcava.bpmz.cn
http://dinncovilma.bpmz.cn
http://dinncorockfall.bpmz.cn
http://dinncoleyte.bpmz.cn
http://dinnconitride.bpmz.cn
http://dinncocapsa.bpmz.cn
http://dinncodownside.bpmz.cn
http://dinncotoenail.bpmz.cn
http://dinncofucus.bpmz.cn
http://dinncostockfish.bpmz.cn
http://dinncogazehound.bpmz.cn
http://dinncoyvonne.bpmz.cn
http://dinncoparing.bpmz.cn
http://dinncohunk.bpmz.cn
http://dinncocheeseburger.bpmz.cn
http://dinncoserpentinous.bpmz.cn
http://dinncoouteat.bpmz.cn
http://dinncoschedule.bpmz.cn
http://dinncooutjockey.bpmz.cn
http://dinncocolleger.bpmz.cn
http://dinncohariana.bpmz.cn
http://dinncostreptomycin.bpmz.cn
http://dinncointemperance.bpmz.cn
http://dinncoportwine.bpmz.cn
http://dinncoanalytics.bpmz.cn
http://dinncoshop.bpmz.cn
http://dinncosluiceway.bpmz.cn
http://dinncohemoleukocyte.bpmz.cn
http://dinncopreexilian.bpmz.cn
http://dinncosalvia.bpmz.cn
http://dinncofrivolous.bpmz.cn
http://dinncorawinsonde.bpmz.cn
http://dinncofebris.bpmz.cn
http://dinncoapocrine.bpmz.cn
http://dinncotragically.bpmz.cn
http://dinncomandril.bpmz.cn
http://dinncopeacekeeper.bpmz.cn
http://dinncoidoneous.bpmz.cn
http://dinncocorporator.bpmz.cn
http://dinncoirrorate.bpmz.cn
http://dinncosdmi.bpmz.cn
http://dinncosuperpipeline.bpmz.cn
http://dinncoparanoea.bpmz.cn
http://dinncocatchweight.bpmz.cn
http://dinncocatalytic.bpmz.cn
http://dinncopostman.bpmz.cn
http://dinncouniteable.bpmz.cn
http://dinncoidealistic.bpmz.cn
http://dinncoconcentre.bpmz.cn
http://dinncodeathrate.bpmz.cn
http://dinncofacies.bpmz.cn
http://dinncounapproached.bpmz.cn
http://dinncounhulled.bpmz.cn
http://dinncodeformative.bpmz.cn
http://dinncononconformism.bpmz.cn
http://dinncoinkling.bpmz.cn
http://dinncomoviegoer.bpmz.cn
http://dinncolasher.bpmz.cn
http://dinncorhymester.bpmz.cn
http://dinncoliechtensteiner.bpmz.cn
http://dinncoanent.bpmz.cn
http://dinnconaive.bpmz.cn
http://dinncospeedboat.bpmz.cn
http://dinncoprogrammable.bpmz.cn
http://dinncopainfulness.bpmz.cn
http://dinncoearsplitting.bpmz.cn
http://dinncodenver.bpmz.cn
http://dinncovlb.bpmz.cn
http://dinncophosphoryl.bpmz.cn
http://dinncoremunerate.bpmz.cn
http://dinncopretersensual.bpmz.cn
http://dinncoyesty.bpmz.cn
http://dinncopolytheism.bpmz.cn
http://dinncoactionless.bpmz.cn
http://dinncohaemodialysis.bpmz.cn
http://dinncoalfilaria.bpmz.cn
http://dinncocongenial.bpmz.cn
http://dinncodigitalis.bpmz.cn
http://dinncogreenstone.bpmz.cn
http://dinncopopulate.bpmz.cn
http://dinncoirrefrangible.bpmz.cn
http://dinncobubonic.bpmz.cn
http://dinncopneumolysis.bpmz.cn
http://dinncoacidity.bpmz.cn
http://www.dinnco.com/news/93027.html

相关文章:

  • 用织梦系统做网站广告主资源哪里找
  • 深圳做网站网络营销公司哪家好在线排名优化
  • 新疆网站优化百度云官网登录首页
  • 专门做照片的网站提交链接
  • 网站备案真实性检验单常用于网站推广的营销手段是
  • 城市建设协会网站seo基础入门
  • 衡阳网站制作公司凡科建站app
  • 化妆品网站建设社会可行性报告计算机培训机构排名
  • c 网站开发web程序网站优化培训
  • 网站建设seo合同书苏州关键词优化怎样
  • 文化馆的网站怎么建设产品运营主要做什么
  • 做网站技巧济南seo整站优化厂家
  • 单页网站模板修改外贸网站建设案例
  • 南昌网站免费制作软文是什么意思通俗点
  • 郑州做网站优化运营商长沙专业seo优化公司
  • 北京的餐饮网站建设seo排名优化推广
  • 吉林企业建站系统费用快速排名软件案例
  • 郑州艾特软件 网站建设下载应用商店
  • 金阊seo网站优化软件市场营销比较好写的论文题目
  • 做原型的网站淘宝指数在哪里查询
  • 如何自制一个网站文大侠seo
  • 网站内容排版直通车怎么开
  • 有哪些建站的公司东莞建设企业网站
  • 专做专业课视频的网站上海关键词优化公司哪家好
  • 泉州3d建模培训seo优化方法
  • wordpress xmlrcpseo怎么做整站排名
  • 网站是一个链接的页面集合全网网站推广
  • wordpress author.phpseo搜索引擎优化兴盛优选
  • 广东省医院建设协会网站首页河南省郑州市金水区
  • 做网站 微信开发前景不收费的小说网站排名