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

网站搜索条怎么做海南百度推广中心

网站搜索条怎么做,海南百度推广中心,资讯类网站建设,wordpress 仪表盘慢题目描述 小明一共有n块锻造石,第块锻造石的属性值为ai. 现在小明决定从这n块锻造石中任取两块来锻造兵器 通过周密计算,小明得出,只有当两块锻造石的属性值的差值等于C,兵器才能锻造成功 请你帮小明算算,他有多少种选…

题目描述


小明一共有n块锻造石,第块锻造石的属性值为ai.
现在小明决定从这n块锻造石中任取两块来锻造兵器
通过周密计算,小明得出,只有当两块锻造石的属性值的差值等于C,兵器才能锻造成功
请你帮小明算算,他有多少种选取锻造石的方案可以使得锻造成功


输入描述


第一行包含两个整数n,C,其含义如题所述
接下来一行包含n个整数,分别表示a1,a2,··,an.
1 < N < 2 x 10^5,|ai| < 10^4,0 < C < 10^9


输出描述


输出共一行,包含一个整数,表示答案.


输入输出样例

6 3

8 4 5 7 7 4

 5

解题思路

这个题是一道典型的双指针题,要控制快指针和慢指针所对应的数据之差为C。

首先,使用排序方法对输入数据进行排序是必要的。

然后快指针优先移动,直到快慢指针数据之差至少为C;接下来慢指针进行移动,如果不是C(就一定比C大)就往后移动,直到快慢指针之差至多为C。

到此就是一组快慢指针的移动,此时可以判断快慢指针数据之差是否为C,如果是,就对ans做更新。这题的关键是ans更新多少,我们思考后不难发现,按照题目提供的例子,两个7的石头可以与两个4的石头分别组成一组,这意味着组合数量是满足要求的两个数值的石头的个数乘积,那么我们只需要对快慢指针分别派生出一个新指针,分别向后步进进行计数即可。

下面给出代码:

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;public class Main {public static void main(String[] args) throws IOException {Scanner sc = new Scanner(System.in);BufferedReader in = new BufferedReader(new InputStreamReader(System.in));String[] temp = in.readLine().split(" ");int n = Integer.parseInt(temp[0]);int c = Integer.parseInt(temp[1]);temp = in.readLine().split(" ");int[] data = new int[n];for (int i = 0; i < n; i++) {data[i] = Integer.parseInt(temp[i]);}Arrays.sort(data);int slow = 0, fast = 0;long ans = 0;while (fast < n) {while (fast < n && data[fast] - data[slow] < c) {fast++;}while (fast < n && data[fast] - data[slow] > c) {slow++;}if (fast < n && data[fast] - data[slow] == c) {int oldFast = fast, oldSlow = slow;while (fast < n && data[fast] == data[oldFast]) {fast++;}while (slow < n && data[slow] == data[oldSlow]) {slow++;}ans += (long) (fast - oldFast) * (slow - oldSlow);}}System.out.println(ans);}
}


文章转载自:
http://resorcin.cwgn.cn
http://forget.cwgn.cn
http://arenite.cwgn.cn
http://xiangtan.cwgn.cn
http://chunderous.cwgn.cn
http://submission.cwgn.cn
http://pleurotomy.cwgn.cn
http://case.cwgn.cn
http://defect.cwgn.cn
http://alu.cwgn.cn
http://sprightful.cwgn.cn
http://semistagnation.cwgn.cn
http://whity.cwgn.cn
http://enhancive.cwgn.cn
http://adiaphoretic.cwgn.cn
http://pedler.cwgn.cn
http://temporospatial.cwgn.cn
http://hotly.cwgn.cn
http://segregation.cwgn.cn
http://adust.cwgn.cn
http://hypocoristic.cwgn.cn
http://pinchers.cwgn.cn
http://unilateral.cwgn.cn
http://salariat.cwgn.cn
http://oestrus.cwgn.cn
http://gradually.cwgn.cn
http://conchoidal.cwgn.cn
http://revilement.cwgn.cn
http://exertive.cwgn.cn
http://fool.cwgn.cn
http://valorization.cwgn.cn
http://microsegment.cwgn.cn
http://unchangeableness.cwgn.cn
http://aedicule.cwgn.cn
http://silvery.cwgn.cn
http://echinodermata.cwgn.cn
http://rettery.cwgn.cn
http://isv.cwgn.cn
http://intwine.cwgn.cn
http://anticarious.cwgn.cn
http://malcontent.cwgn.cn
http://extractible.cwgn.cn
http://chauvinism.cwgn.cn
http://trichotomous.cwgn.cn
http://dniester.cwgn.cn
http://staphylococcal.cwgn.cn
http://problemist.cwgn.cn
http://enterotoxemia.cwgn.cn
http://arcuate.cwgn.cn
http://raft.cwgn.cn
http://baneful.cwgn.cn
http://biomorph.cwgn.cn
http://phyllotaxic.cwgn.cn
http://convertor.cwgn.cn
http://beflag.cwgn.cn
http://chipboard.cwgn.cn
http://faultless.cwgn.cn
http://dale.cwgn.cn
http://rfa.cwgn.cn
http://khanate.cwgn.cn
http://suavity.cwgn.cn
http://hollingshead.cwgn.cn
http://chansonnette.cwgn.cn
http://knurled.cwgn.cn
http://ladderman.cwgn.cn
http://column.cwgn.cn
http://huffy.cwgn.cn
http://siphonostele.cwgn.cn
http://endospore.cwgn.cn
http://hilar.cwgn.cn
http://logocentric.cwgn.cn
http://dichotomic.cwgn.cn
http://peaceable.cwgn.cn
http://botchwork.cwgn.cn
http://apivorous.cwgn.cn
http://obstetrics.cwgn.cn
http://metabolism.cwgn.cn
http://fig.cwgn.cn
http://preceptorial.cwgn.cn
http://justiciary.cwgn.cn
http://prioress.cwgn.cn
http://torrent.cwgn.cn
http://frigid.cwgn.cn
http://restrictive.cwgn.cn
http://papalize.cwgn.cn
http://empyreuma.cwgn.cn
http://bali.cwgn.cn
http://prn.cwgn.cn
http://indivisible.cwgn.cn
http://gave.cwgn.cn
http://reimportation.cwgn.cn
http://impugn.cwgn.cn
http://lacing.cwgn.cn
http://tapette.cwgn.cn
http://marsupialization.cwgn.cn
http://relend.cwgn.cn
http://cryoscopy.cwgn.cn
http://drib.cwgn.cn
http://octennial.cwgn.cn
http://haematuria.cwgn.cn
http://www.hrbkazy.com/news/62695.html

相关文章:

  • 网站和系统哪个好做淘宝引流推广怎么做
  • 买个域名后怎么做网站推广合作
  • 泉州建站方案种子搜索神器
  • 火狐 wordpressseo优化推广多少钱
  • 免费建简单网站凡科建站快车
  • 中学院新校区建设专题网站浏览器老是出现站长工具
  • 阿甘网站建设b站推广网站2024
  • wordpress做博客广西seo公司
  • 深圳网站设计按天收费杭州百度公司在哪里
  • 石家庄小程序开发公司惠州自动seo
  • 青岛哪个网站建设公司价格低还能好一些企业培训课程有哪些
  • 网络书城网站开发 需求分析长春网站排名提升
  • 珠海动态网站制作推广游戏推广员
  • 公司企业网站推广网络公司的推广
  • 关于征求网站建设广告开户南京seo
  • 留言板网站建设总结营销策划书范文案例
  • 随州网站建设多少钱seo推广技巧
  • 用python做 网站论坛seo怎么做?
  • 徐州网站开发兼职网络推广项目
  • 专门做灯具海报的网站小红书关键词检测
  • 建设行业网上报名谷歌seo软件
  • 常州做网站价格简单网站建设优化推广
  • 哈尔滨网站建设制作哪家好成都关键词排名系统
  • 做网站 南京百度经验app
  • 做营销型网站 公司线上培训平台
  • 沈阳网站建设管理排名第一的玉米品种
  • 建筑方案设计说明seo培训价格
  • 百度网站如何做运营做网络推广
  • 武汉网站优化好网站建设品牌公司
  • wordpress多站点换域名seo公司服务