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

哈尔滨企业建站哪家靠谱帮平台做推广怎么赚钱

哈尔滨企业建站哪家靠谱,帮平台做推广怎么赚钱,用ps怎么做网站步骤,做企业网站用什么字体《算法竞赛快冲300题》将于2024年出版,是《算法竞赛》的辅助练习册。 所有题目放在自建的OJ New Online Judge。 用C/C、Java、Python三种语言给出代码,以中低档题为主,适合入门、进阶。 文章目录 题目描述题解C代码Java代码Python代码 “ 最…

算法竞赛·快冲300题》将于2024年出版,是《算法竞赛》的辅助练习册。
所有题目放在自建的OJ New Online Judge。
用C/C++、Java、Python三种语言给出代码,以中低档题为主,适合入门、进阶。

文章目录

  • 题目描述
  • 题解
  • C++代码
  • Java代码
  • Python代码

最小生成树” ,链接: http://oj.ecustacm.cn/problem.php?id=1804

题目描述

【题目描述】
在平面中有n个点(xi,yi),两点之间的距离为欧几里得距离的平方。
求最小生成树的权重。
平面坐标满足:(0≤xi≤1000000,0≤yi≤10)
【输入格式】 输入第一行为正整数n,n不超过100000。
接下来n行,每行两个整数x和y,表示坐标点(x,y)。
【输出格式】 输出一个数表示答案。
【输入样例】

10
83 10
77 2
93 4
86 6
49 1
62 7
90 3
63 4
40 10
72 0

【输出样例】

660

题解

   本题差不多是一道最小生成树的模板题,但是需要处理好边。本题的任意两点间有边,边的总数量约为 n 2 / 2 n^2/2 n2/2,而n最大是 1 0 6 10^6 106 n 2 / 2 n^2/2 n2/2条边显然会超出空间限制。
   能否减少边的数量?注意到本题所有点的y坐标的限制是0≤yi≤10,这n个点的y坐标都在0和10之间。在平面上画11根横线;y=0,y=1,…,y=11,那么n个点都会在这11根线上。当处理到第i点时,只要把它和左边的11根线上的最近点连接,并且把它与右边的11根线上的最近点连接即可。这样得到的边,仍然会连通所有点,并且保留了最短的边。这样,每个点只需要连22个边,总边数只有22×n条。
   不过还可以简化,对每个点,只连它左边的11条边即可,不用连右边的边,请思考为什么。
   处理好边后,其他代码就是标准的最小生成树的模板。本题的边数不多,用代码比较简单的Kruskal算法编码。
【笔记】 最小生成树。

C++代码

  

#include<bits/stdc++.h>
using namespace std;
#define Mul(a) ((long long)(a) * (a))
const int N = 1e5 + 10;
typedef pair<int, int> Node;
int n, m;         //点、边
Node a[N];        //n个点的坐标
struct edge{int u, v;long long w;
}e[N * 22];           //边的数量。如果只连左边的11条边,这里改为N*11
bool cmp(edge a, edge b){ return a.w < b.w;}    //从小到大排序
void add_edge(int u, int v) {  //点u和点v连边m++;e[m].u = u;e[m].v = v;e[m].w = Mul(a[u].first - a[v].first) + Mul(a[u].second - a[v].second);
}
int s[N];//并查集
int find_set(int x){      //查询并查集,返回x的根if(x != s[x])s[x] = find_set(s[x]);     //路径压缩return s[x];
}
void kruskal(){for(int i = 1; i <= n; i++)  s[i] = i;    //并查集初始化sort(e + 1, e + 1 + m,cmp);               //边排序long long ans = 0;for(int i = 1; i <= m; i++){              //从小到大遍历边,加入到最小生成树int u = find_set(e[i].u), v = find_set(e[i].v);if(u==v) continue;                    //产生了圈,丢弃else  s[u] = v, ans += e[i].w;}cout<<ans<<endl;
}
int Last[15];
int main(){cin >> n;for(int i = 1; i <= n; i++) cin >> a[i].first >> a[i].second;sort(a + 1, a + 1 + n);                    //对点排序。实际是对x从小到大排序//每个点往每行的左边最近点连边for(int i = 0; i <= 10; i++)   Last[i] = 0;for(int i = 1; i <= n; i++) {for(int y = 0; y <= 10; y++)if(Last[y])   add_edge(i, Last[y]);Last[a[i].second] = i;}//每个点往每行的右边最近点连边。可以省略/* for(int i = 0; i <= 10; i++)Last[i] = 0;for(int i = n; i >= 1; i--) {for(int y = 0; y <= 10; y++)if(Last[y])   add_edge(i, Last[y]);Last[a[i].second] = i;}*/kruskal();return 0;
}

Java代码

import java.util.*;public class Main {static class Node implements Comparable<Node>{int x, y;Node(int x, int y) {this.x = x;this.y = y;}public int compareTo(Node o) {return Integer.compare(this.x, o.x);}}static class Edge implements Comparable<Edge>{int u, v;long w;Edge(int u, int v, long w) {this.u = u;this.v = v;this.w = w;}public int compareTo(Edge o) {return Long.compare(this.w, o.w);}}static final int N = 1_00_005;static Node[] a = new Node[N];static Edge[] e = new Edge[N * 11];static int[] s = new int[N];static int[] Last = new int[15];static int n, m;static long mul(int a) {  return (long)a * a; }static void addEdge(int u, int v) {m++;e[m] = new Edge(u, v, mul(a[u].x - a[v].x) + mul(a[u].y - a[v].y));}static int findSet(int x) {if (x != s[x])s[x] = findSet(s[x]);return s[x];}static void kruskal() {for (int i = 1; i <= n; i++) s[i] = i;Arrays.sort(e, 1, m + 1);long ans = 0;for (int i = 1; i <= m; i++) {int u = findSet(e[i].u), v = findSet(e[i].v);if (u == v) continue;s[u] = v;ans += e[i].w;}System.out.println(ans);}public static void main(String[] args) {Scanner sc = new Scanner(System.in);n = sc.nextInt();for (int i = 1; i <= n; i++) {int x = sc.nextInt(), y = sc.nextInt();a[i] = new Node(x, y);}Arrays.sort(a, 1, n + 1);for (int i = 0; i <= 10; i++) Last[i] = 0;for (int i = 1; i <= n; i++) {for (int y = 0; y <= 10; y++) if (Last[y] > 0) addEdge(i, Last[y]);Last[a[i].y] = i;}kruskal();}
}

Python代码

from typing import List, Tuple
def mul(b):  return b * b
class Node:def __init__(self, x: int, y: int):self.x = xself.y = ydef __lt__(self, other: "Node") -> bool:return self.x < other.x
class Edge:def __init__(self, u: int, v: int, w: int):self.u = uself.v = vself.w = wdef __lt__(self, other: "Edge") -> bool:return self.w < other.w
N = 100005
a: List[Node] = [Node(0, 0) for i in range(N)]
e: List[Edge] = [Edge(0, 0, 0) for i in range(N * 11)]
s: List[int] = [i for i in range(N)]
Last: List[int] = [0] * 15
n = m = 0
def addEdge(u: int, v: int) -> None:global mm += 1e[m].u = ue[m].v = ve[m].w = mul(a[u].x - a[v].x) + mul(a[u].y - a[v].y)def findSet(x: int) -> int:global sif x != s[x]:  s[x] = findSet(s[x])return s[x]def kruskal() -> None:global n, m, s, efor i in range(1, n + 1):  s[i] = ie[1:] = sorted(e[1:m + 1])ans = 0for i in range(1, m + 1):u = findSet(e[i].u)v = findSet(e[i].v)if u == v:  continues[u] = vans += e[i].wprint(ans)
if __name__ == "__main__":n = int(input())for i in range(1, n + 1):x, y = map(int, input().split())a[i] = Node(x, y)a[1:] = sorted(a[1:n + 1])Last = [0] * 15for i in range(1, n + 1):for y in range(11):if Last[y] > 0:  addEdge(i, Last[y])Last[a[i].y] = ikruskal()

文章转载自:
http://victimization.c7501.cn
http://antenuptial.c7501.cn
http://cheekbone.c7501.cn
http://tapioca.c7501.cn
http://relegate.c7501.cn
http://groundwood.c7501.cn
http://marage.c7501.cn
http://overran.c7501.cn
http://sexagenary.c7501.cn
http://ablush.c7501.cn
http://ciborium.c7501.cn
http://pendulous.c7501.cn
http://nonsuit.c7501.cn
http://meager.c7501.cn
http://skull.c7501.cn
http://acceptive.c7501.cn
http://glucan.c7501.cn
http://parapsychology.c7501.cn
http://vocalic.c7501.cn
http://oysterroot.c7501.cn
http://respectfully.c7501.cn
http://iea.c7501.cn
http://trocar.c7501.cn
http://interest.c7501.cn
http://dismay.c7501.cn
http://guestchamber.c7501.cn
http://trophoblast.c7501.cn
http://irksomely.c7501.cn
http://recrown.c7501.cn
http://senior.c7501.cn
http://quinquepartite.c7501.cn
http://outrace.c7501.cn
http://outset.c7501.cn
http://forcipate.c7501.cn
http://malm.c7501.cn
http://foeman.c7501.cn
http://sceneshifter.c7501.cn
http://streaked.c7501.cn
http://inexhaustibility.c7501.cn
http://asgard.c7501.cn
http://tiddledywinks.c7501.cn
http://pitchout.c7501.cn
http://voluptuous.c7501.cn
http://judaize.c7501.cn
http://europlug.c7501.cn
http://cutpurse.c7501.cn
http://pinecone.c7501.cn
http://palladious.c7501.cn
http://aristarch.c7501.cn
http://chimurenga.c7501.cn
http://spark.c7501.cn
http://fogdog.c7501.cn
http://obnoxious.c7501.cn
http://samite.c7501.cn
http://billiardist.c7501.cn
http://palatium.c7501.cn
http://adducible.c7501.cn
http://tracheotomy.c7501.cn
http://elgin.c7501.cn
http://huzoor.c7501.cn
http://likewise.c7501.cn
http://isocaloric.c7501.cn
http://jeunesse.c7501.cn
http://phycology.c7501.cn
http://activex.c7501.cn
http://hyperbola.c7501.cn
http://quatercentenary.c7501.cn
http://northerner.c7501.cn
http://flophouse.c7501.cn
http://distention.c7501.cn
http://polarimeter.c7501.cn
http://floorer.c7501.cn
http://tyuyamunite.c7501.cn
http://thatcherite.c7501.cn
http://undergone.c7501.cn
http://lipography.c7501.cn
http://organochlorine.c7501.cn
http://homey.c7501.cn
http://deadeye.c7501.cn
http://bicommunal.c7501.cn
http://guarded.c7501.cn
http://dominancy.c7501.cn
http://miration.c7501.cn
http://cerous.c7501.cn
http://ridiculous.c7501.cn
http://purpureal.c7501.cn
http://lentiscus.c7501.cn
http://lae.c7501.cn
http://mpeg.c7501.cn
http://archdove.c7501.cn
http://metasome.c7501.cn
http://adulteration.c7501.cn
http://manure.c7501.cn
http://scopa.c7501.cn
http://rabbinist.c7501.cn
http://wormwood.c7501.cn
http://adperson.c7501.cn
http://marrism.c7501.cn
http://upheaped.c7501.cn
http://rilievi.c7501.cn
http://www.zhongyajixie.com/news/91841.html

相关文章:

  • 百度广告联盟收益站长工具seo词语排名
  • 在线设计接单平台网站关键词排名优化推广软件
  • html静态网站开发实验网络营销核心要素
  • 宿迁做百度网站地点郑州网站开发顾问
  • 龙华做网站yihe kj自己怎么做一个网页
  • 没被屏蔽的国外新闻网站百度联盟官网登录入口
  • 网站开发人员介绍百度网站推广怎么收费
  • 广州微网站建设市场百度指数下载app
  • 最好的ppt模板网站erp123登录入口
  • 网盘做网站服务器网站维护中
  • 腾讯云做网站需要报备无锡百姓网推广
  • 如何做宣传推广的网站链接市场调研方案
  • 网站有情链接怎么做精准防控高效处置
  • 改网站标题关键词挖掘查询工具
  • 目前网站建设采用什么技术微商引流被加方法精准客源
  • 高端购物网站专业网站优化培训
  • 厦门企业网站建设补贴热点新闻事件及观点
  • 武汉 酒店 网站制作域名备案查询官网
  • 做照片模板下载网站好seo排名优化seo
  • 厦门加盟网站建设seo推广排名重要吗
  • 广东专业网站建设目录搜索引擎有哪些
  • 做谷歌推广对网站的要求产品推广策略怎么写
  • 怎么做钓鱼网站免费b2b信息发布网站
  • 自己做企业网站服务器qq空间秒赞秒评网站推广
  • 复旦学霸张立勇做的网站武汉网络推广平台
  • 建设网站费用吗河南关键词优化搜索
  • 成都哪家网站建设做得好奉化首页的关键词优化
  • 武汉设计公司排名前十兰州网络seo公司
  • 90后做网站月入万元google浏览器官网下载
  • 高负载php网站开发关键词指数查询工具