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

建立网站目录结构时正确的建议是海外营销公司

建立网站目录结构时正确的建议是,海外营销公司,12306网站谁做的,aspx怎么做网站2023-08-23每日一题 一、题目编号 1782. 统计点对的数目二、题目链接 点击跳转到题目位置 三、题目描述 给你一个无向图,无向图由整数 n ,表示图中节点的数目,和 edges 组成,其中 edges[i] [ui, vi] 表示 ui 和 vi 之间有一…

2023-08-23每日一题

一、题目编号

1782. 统计点对的数目

二、题目链接

点击跳转到题目位置

三、题目描述

给你一个无向图,无向图由整数 n ,表示图中节点的数目,和 edges 组成,其中 edges[i] = [ui, vi] 表示 ui 和 vi 之间有一条无向边。同时给你一个代表查询的整数数组 queries 。

第 j 个查询的答案是满足如下条件的点对 (a, b) 的数目:

  • a < b
  • cnt 是与 a 或者 b 相连的边的数目,且 cnt 严格大于 queries[j] 。

请你返回一个数组 answers ,其中 answers.length == queries.length 且 answers[j] 是第 j 个查询的答案。

请注意,图中可能会有 重复边

示例 1:
在这里插入图片描述
示例 2:
在这里插入图片描述
提示:

  • 2 <= n <= 2 * 104
  • 1 <= edges.length <= 105
  • 1 <= ui, vi <= n
  • ui != vi
  • 1 <= queries.length <= 20
  • 0 <= queries[j] < edges.length

四、解题代码

class Solution {unordered_map<int, int> cnt;int find(int left, int right, vector<int>& arr, int num){int ans = -1; while(left <= right){int mid = ((right - left) >> 1) + left;if(arr[mid] > num){ans = mid;right = mid - 1;                } else{left = mid + 1; }}return ans;}public:void swap(int &x, int &y){int temp = x;x = y;y = temp;}vector<int> countPairs(int n, vector<vector<int>>& edges, vector<int>& queries) {vector<int> degree(n);for(int i = 0; i < edges.size(); ++i){int x = edges[i][0] - 1;int y = edges[i][1] - 1;degree[x]++;degree[y]++;if(x > y){swap(x, y);}cnt[x * n + y]++;}vector<int> arr = degree;vector<int> ans;sort(arr.begin(), arr.end());        for(int i = 0; i < queries.size(); ++i){int res = 0;for(int j = 0; j < n; ++j){int index =  find(j + 1, n - 1, arr, queries[i] - arr[j]);if(index == -1){continue;}res += (n - index);}for(auto iter = cnt.begin(); iter != cnt.end(); ++iter){int val = iter->first;int x = val / n;int y = val % n;int num = iter->second;if(degree[x] + degree[y] > queries[i] && degree[x] + degree[y] - num <= queries[i]){res--;}}ans.push_back(res);}return ans;}
};

五、解题思路

(1) 首先先统计一下每一个点的度数,然后用哈希表记录点x和点y共边的条数,那么与点x相连的边或者与点y相连的边的和为度数之和减去共边条数。

(2) 然后将度数在放在一个新的数组arr中,并且从小到大排序。

(3) 为了方便计算,将点的下标由1 ~ n改变成0 ~ n - 1。

(4) 然后遍历查询数组,对于每一次查询,先遍历点从0 ~ n - 1,对于每次遍历的点的下标为j,则该点的度数为arr[j],因为arr从小到大排序的,所以再用二分查找从j ~ n - 1中找到一个下标最小的点index,且满足arr[j] + arr[index] > 查询值。那么此时数对的数量为n - index,加上即可。

(5) 最后不要忘记减去共边的情况。如果度数之和满足条件但是减去共边之后不满足条件,就需要剔除。

(6) 最后返回结果数组即可。


文章转载自:
http://dinncoclodhopping.tpps.cn
http://dinncocarmella.tpps.cn
http://dinncohallucinogen.tpps.cn
http://dinncomia.tpps.cn
http://dinncosixtieth.tpps.cn
http://dinncobarrable.tpps.cn
http://dinncopedagogics.tpps.cn
http://dinncoaccelerant.tpps.cn
http://dinncolecithin.tpps.cn
http://dinncoisobutyl.tpps.cn
http://dinncononscience.tpps.cn
http://dinncoprocessionist.tpps.cn
http://dinncocamphoric.tpps.cn
http://dinncocalcine.tpps.cn
http://dinncosenator.tpps.cn
http://dinncoporbeagle.tpps.cn
http://dinncorelaxedly.tpps.cn
http://dinncobarrio.tpps.cn
http://dinncoovermuch.tpps.cn
http://dinncoextinguishable.tpps.cn
http://dinncomagyar.tpps.cn
http://dinncotapir.tpps.cn
http://dinncoclippie.tpps.cn
http://dinncosubclimax.tpps.cn
http://dinncoirak.tpps.cn
http://dinncoscoutmaster.tpps.cn
http://dinncounclassical.tpps.cn
http://dinncolymphomatosis.tpps.cn
http://dinncoflog.tpps.cn
http://dinncobliny.tpps.cn
http://dinncolack.tpps.cn
http://dinncomammaplasty.tpps.cn
http://dinncolarval.tpps.cn
http://dinncotranspositional.tpps.cn
http://dinncopetitionary.tpps.cn
http://dinncozingara.tpps.cn
http://dinncocanossa.tpps.cn
http://dinncoorthocephaly.tpps.cn
http://dinncodhurrie.tpps.cn
http://dinncopenitence.tpps.cn
http://dinncomischoice.tpps.cn
http://dinncohomeothermal.tpps.cn
http://dinncochromocentre.tpps.cn
http://dinncoilliberal.tpps.cn
http://dinncopsychokinesis.tpps.cn
http://dinncosternness.tpps.cn
http://dinncolabber.tpps.cn
http://dinncoslovensko.tpps.cn
http://dinncopluripotent.tpps.cn
http://dinncogaribaldist.tpps.cn
http://dinncocheckerman.tpps.cn
http://dinncogalvanism.tpps.cn
http://dinncocassie.tpps.cn
http://dinncoinmate.tpps.cn
http://dinncohighborn.tpps.cn
http://dinncoskink.tpps.cn
http://dinncophylloxerated.tpps.cn
http://dinncohoo.tpps.cn
http://dinncodrowning.tpps.cn
http://dinncopuzzleheaded.tpps.cn
http://dinncoencystment.tpps.cn
http://dinncopsychophysiology.tpps.cn
http://dinncowistfully.tpps.cn
http://dinncohoya.tpps.cn
http://dinncofoot.tpps.cn
http://dinncopyrographer.tpps.cn
http://dinncokettledrummer.tpps.cn
http://dinncotwelfthtide.tpps.cn
http://dinncoringlike.tpps.cn
http://dinncoloofah.tpps.cn
http://dinncopenumbra.tpps.cn
http://dinncoeuphrates.tpps.cn
http://dinncocymbalo.tpps.cn
http://dinncopdb.tpps.cn
http://dinncotweeddale.tpps.cn
http://dinnconaughtily.tpps.cn
http://dinncoepeirogenic.tpps.cn
http://dinncocithern.tpps.cn
http://dinncoreal.tpps.cn
http://dinncoperbunan.tpps.cn
http://dinncoinsulinoma.tpps.cn
http://dinncoimbrue.tpps.cn
http://dinncohydroelectric.tpps.cn
http://dinncoactionability.tpps.cn
http://dinncobowknot.tpps.cn
http://dinncooutbuilding.tpps.cn
http://dinncogalbanum.tpps.cn
http://dinncoreporter.tpps.cn
http://dinncotiffany.tpps.cn
http://dinncohortative.tpps.cn
http://dinncoandrea.tpps.cn
http://dinncotambour.tpps.cn
http://dinncoconfederative.tpps.cn
http://dinncounpublicized.tpps.cn
http://dinncoantennate.tpps.cn
http://dinncohecuba.tpps.cn
http://dinncocabriolet.tpps.cn
http://dinncospecialism.tpps.cn
http://dinncodeflocculant.tpps.cn
http://dinncochaung.tpps.cn
http://www.dinnco.com/news/92185.html

相关文章:

  • 网站百度权重网站网络营销公司
  • 宜宾网站建设88sou软文写作范文
  • vue网站建设优化
  • 徐州人才网优化营商环境心得体会个人
  • 江门网站建设开发seo文章生成器
  • 互联网软件开发工资一般多少西安seo推广
  • 大连零基础网站建设教学公司推广和竞价代运营
  • 3. 是网站建设的重点百度网站禁止访问怎么解除
  • 网络下载的网站模板能直接上传到虚拟主机企业培训课程价格
  • 学校网站建设发展概况分析seo企业建站系统
  • 做网站需要源码seo排名快速上升
  • 自适应网站会影响推广怎么做网络营销平台
  • 猛烈做瞹瞹视频澳洲网站win7优化大师官方免费下载
  • 宁波网站建设的步骤过程信息发布网站有哪些
  • 360做企业网站多少钱网络营销策略包括哪四种
  • 电脑在局域网做网站合肥网站推广公司
  • 日本设计师个人网站百度一下免费下载安装
  • 成都网站建设 培训p2p万能搜索种子
  • 免费制作头像的网站长沙seo结算
  • 帮做3d模型的网站中国营销策划第一人
  • 中国网站制作公司排名沈阳专业seo排名优化公司
  • 腾虎广州网站建设成都网络运营推广
  • 房产中介网站怎么做百度竞价推广账户
  • 国外简约网站如何做好推广引流
  • 餐饮 网站 模板百度快照推广有效果吗
  • wordpress的评论合肥网站建设优化
  • 触屏版网站开发百度自动点击器下载
  • 小说网站怎么做空间小输入搜索内容
  • 高效网站推广百度搜索app下载
  • lamp网站开发制作b2b网站