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

网上做调查网站有哪些凡科网

网上做调查网站有哪些,凡科网,酒类做网站,深圳外贸响应式网站建设目录 迪杰斯特拉模板(用来求一个点出发到其它点的最短距离): 克鲁斯卡尔模板(用来求最小生成树): 题目一(蓝桥王国): 题目二(随机数据下的最短路径&#…

目录

迪杰斯特拉模板(用来求一个点出发到其它点的最短距离):

克鲁斯卡尔模板(用来求最小生成树):

题目一(蓝桥王国):

题目二(随机数据下的最短路径): 

题目三(出差):

题目四(聪明的猴子):

 题目六(机房):

迪杰斯特拉模板(用来求一个点出发到其它点的最短距离):

#include<iostream>
#include<queue>
#include<vector>
#include<cstring>
using namespace std;
typedef long long ll;
const ll N = 3e5 + 10, M = 1e6 + 10, inf = 1e14;
struct  node
{ll v, w;bool operator <(const node& y) const//重载一个<,用于优先队列排序{return w > y.w;//小到大}
};
int n, m;
priority_queue<node>q;
vector<node> e[N];
ll dis[N], vis[N];
void Dij()
{dis[1] = 0;//从1号点出发,表示从1到1距离为0q.push({ 1,dis[1] });//1号点以及到1的距离入队while (q.size()){int u = q.top().v;//取最小边相连的点出队q.pop();if (vis[u])//访问过则跳过continue;vis[u] = 1;//没访问赋为访问for (auto i : e[u])//遍历以u为出发点的边{int v = i.v, w = i.w;//取其相连的点及权值if (dis[v] > dis[u] + w)//经过u点到v点的权值小于之前的权值则更新{dis[v] = dis[u] + w;q.push({ v,dis[v] });//v点以及到v的距离}}}}
int main()
{cin >> n >> m;fill(dis+1, dis+1+n, inf);//赋值一个无穷大,表示没有连接for (int i = 1; i <= m; i++){int x, y, w;cin >> x >> y >> w;e[x].push_back({ y,w });//存入以x出发到y,权值为w}Dij();
}

克鲁斯卡尔模板(用来求最小生成树):

#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
const int N = 1e3+20;
int m, n;
int h[N],f[N],x[N],y[N];
struct edge
{int v1, v2;double w;
};
vector<edge> e;
int find(int k)//查找
{if (f[k] == k)return k;return f[k] = find(f[k]);
}
void  merge(int x, int y)//合并
{x=find(x),y=find(y);if (x!= y)f[x] = f[y];
}
bool cmp(edge a, edge b)
{return a.w < b.w;
}
int main()
{cin >> n;for (int j = 1; j <= n; j++){cin >> x[j] >> y[j]>> h[j];f[j] = j;//初始化并查集根}cin>>m;for (int j = 1; j <= m; j++)//添加边{int v1,v2,w;cin>>v1>>v2>>w;e.push_back({ v1, v2, w });}sort(e.begin(), e.end(), cmp);//边从小到大排序int cnt=0;for (int i = 0; i < e.size(); i++){if (find(e[i].v1) != find(e[i].v2))//不属于一个集合{merge(e[i].v1, e[i].v2);//合并}if (cnt == n-1)//n个点只需要n-1条边,选取n-1条边后,跳出循环break;}
}

题目一(蓝桥王国):

#include<iostream>
#include<queue>
#include<vector>
#include<cstring>
using namespace std;
typedef long long ll;
const ll N = 3e5 + 10, M = 1e6 + 10, inf = 1e14;
struct  node
{ll v, w;bool operator <(const node& y) const//重载一个<,用于优先队列排序{return w > y.w;//小到大}
};
int n, m;
priority_queue<node>q;
vector<node> e[N];
ll dis[N], vis[N];
void Dij()
{dis[1] = 0;//从1号点出发,表示从1到1距离为0q.push({ 1,dis[1] });//1号点以及到1的距离入队while (q.size()){int u = q.top().v;//取最小边相连的点出队q.pop();if (vis[u])//访问过则跳过continue;vis[u] = 1;//没访问赋为访问for (auto i : e[u])//遍历以u为出发点的边{int v = i.v, w = i.w;//取其相连的点及权值if (dis[v] > dis[u] + w)//经过u点到v点的权值小于之前的权值则更新{dis[v] = dis[u] + w;q.push({ v,dis[v] });//v点以及到v的距离}}}}
int main()
{cin >> n >> m;fill(dis+1, dis+1+n, inf);//赋值一个无穷大,表示没有连接for (int i = 1; i <= m; i++){int x, y, w;cin >> x >> y >> w;e[x].push_back({ y,w });//存入以x出发到y,权值为w}Dij();for (int i = 1; i <= n; i++){if (dis[i] >= inf)//无法到达cout << -1 << " ";elsecout << dis[i] << " ";}
}

题目二(随机数据下的最短路径): 

 

#include<iostream>
#include<queue>
#include<vector>
#include<cstring>
using namespace std;
typedef long long ll;
const ll N = 3e5 + 10, M = 1e6 + 10, inf = 1e14;
struct  node
{ll v, w;bool operator <(const node& y) const//重载一个<,用于优先队列排序{return w > y.w;//小到大}
};
int n, m, t;
priority_queue<node>q;
vector<node> e[N];
ll dis[N], vis[N];
void Dij(int t)
{dis[t] = 0;//从t号点出发,表示从t到t距离为0q.push({ t,dis[t] });//t号点以及到t的距离入队while (q.size()){int u = q.top().v;//取最小边相连的点出队q.pop();if (vis[u])//访问过则跳过continue;vis[u] = 1;//没访问赋为访问for (auto i : e[u])//遍历以u为出发点的边{int v = i.v, w = i.w;//取其相连的点及权值if (dis[v] > dis[u] + w)//经过u点到v点的权值小于之前的权值则更新{dis[v] = dis[u] + w;q.push({ v,dis[v] });//v点以及到v的距离}}}}
int main()
{cin >> n >> m>> t;fill(dis+1, dis+1+n, inf);//赋值一个无穷大,表示没有连接for (int i = 1; i <= m; i++){int x, y, w;cin >> x >> y >> w;e[x].push_back({ y,w });//存入以x出发到y,权值为w}Dij(t);//从t点出发for (int i = 1; i <= n; i++){if (dis[i] == inf)//无法到达cout << -1 << " ";elsecout << dis[i] << " ";}
}

题目三(出差):

#include<iostream>
#include<queue>
#include<vector>
#include<cstring>
using namespace std;
typedef long long ll;
const ll N = 3e5 + 10, M = 1e6 + 10, inf = 1e14;
struct  node
{int v, w;bool operator <(const node& y) const//重载一个<,用于优先队列排序{return w > y.w;//小到大}
};
int n, m;
priority_queue<node>q;
vector<node> e[N];
int dis[N], vis[N], time0[N];
void Dij()
{dis[1] = 0;//从1号点出发,表示从1到1距离为0q.push({ 1,dis[1] });//1号点以及到1的距离入队while (q.size()){int u = q.top().v;//取最小边相连的点出队q.pop();if (vis[u])//访问过则跳过continue;vis[u] = 1;//没访问赋为访问for (auto i : e[u])//遍历以u为出发点的边{int v = i.v, w = i.w;//取其相连的点及权值if (dis[v] > dis[u] + w)//经过u点到v点的权值小于之前的权值则更新{dis[v] = dis[u] + w;q.push({ v,dis[v] });//v点以及到v的距离}}}
}
int main()
{cin >> n >> m;for (int i = 1; i <= n; i++)cin >> time0[i];fill(dis + 1, dis + 1 + n, inf);//赋值一个无穷大,表示没有连接for (int i = 1; i <= m; i++){int x, y, w;cin >> x >> y >> w;e[x].push_back({ y,w + time0[y]});//存入以x出发到y,权值为w+隔离时间e[y].push_back({ x,w + time0[x] });//存入以y出发到y,权值为w+隔离时间}Dij();cout << dis[n] - time0[n];//要减掉最后终点的隔离时间
}

题目四(聪明的猴子):

#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
const int N = 1e3+20;
int m, n;
int a[N],f[N],x[N],y[N];
struct edge
{int v1, v2;double w;
};
vector<edge> e;
int find(int k)//查找
{if (f[k] == k)return k;return f[k] = find(f[k]);
}
void  merge(int x, int y)//合并
{x=find(x),y=find(y);if (x!= y)f[x] = f[y];
}
bool cmp(edge a, edge b)
{return a.w < b.w;
}
int main()
{cin >> m;for (int i = 1; i <= m; i++)cin >> a[i];cin >> n;for (int j = 1; j <= n; j++){cin >> x[j] >> y[j];f[j] = j;//初始化并查集根}for(int i=1;i<=n;i++)for (int j = i + 1; j <= n; j++)//添加边{double w = sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));e.push_back({ i, j, w });}sort(e.begin(), e.end(), cmp);//边从小到大排序double maxw = 0.0;//记录最小生成树中最大边int cnt = 0;for (int i = 0; i < e.size(); i++){if (find(e[i].v1) != find(e[i].v2))//不属于一个集合{merge(e[i].v1, e[i].v2);//合并cnt++;maxw = max(maxw, e[i].w);//更新最小生成树中最大边}if (cnt == n-1)//n个点只需要n-1条边,选取n-1条边后,跳出循环break;}int ans = 0;for (int i = 1; i <= m; i++){if (a[i] >= maxw)//有几只猴子大于最小生成树中最大边ans++;}cout << ans;
}

题目五(通电):

#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
const int N = 1e3+20;
int m, n;
int h[N],f[N],x[N],y[N];
struct edge
{int v1, v2;double w;
};
vector<edge> e;
int find(int k)//查找
{if (f[k] == k)return k;return f[k] = find(f[k]);
}
void  merge(int x, int y)//合并
{x=find(x),y=find(y);if (x!= y)f[x] = f[y];
}
bool cmp(edge a, edge b)
{return a.w < b.w;
}
int main()
{cin >> n;for (int j = 1; j <= n; j++){cin >> x[j] >> y[j]>> h[j];f[j] = j;//初始化并查集根}for(int i=1;i<=n;i++)for (int j = i + 1; j <= n; j++)//添加边{double w = sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]))+(h[i]-h[j])*(h[i]-h[j]);e.push_back({ i, j, w });}sort(e.begin(), e.end(), cmp);//边从小到大排序double maxw = 0.0;//记录最小生成树中最大边double ans=0;int cnt=0;for (int i = 0; i < e.size(); i++){if (find(e[i].v1) != find(e[i].v2))//不属于一个集合{merge(e[i].v1, e[i].v2);//合并ans+=e[i].w;//求和maxw = max(maxw, e[i].w);//更新最小生成树中最大边}if (cnt == n-1)//n个点只需要n-1条边,选取n-1条边后,跳出循环break;}printf("%.2lf",ans);
}

 题目六(机房):

#include<iostream>
#include<queue>
#include<vector>
#include<cstring>
using namespace std;
typedef long long ll;
const ll N = 3e5 + 10, M = 1e6 + 10;
struct  node
{ll v, w;bool operator <(const node& y) const//重载一个<,用于优先队列排序{return w > y.w;//小到大}
};
int n, m;
priority_queue<node>q;
vector<node> e[N];
vector<node> temp;
ll dis[N], vis[N], cnt[N];
ll Dij(int u, int end)
{memset(vis, 0, sizeof(vis));memset(dis, 0x3f3f, sizeof(dis));dis[u] = 0;//从u号点出发,表示从u到u距离为0q.push({ u,dis[u] });//u号点以及到u的距离入队while (q.size()){int u = q.top().v;//取最小边相连的点出队q.pop();if (vis[u])//访问过则跳过continue;vis[u] = 1;//没访问赋为访问for (auto i : e[u])//遍历以u为出发点的边{int v = i.v, w = i.w;//取其相连的点及权值if (dis[v] > dis[u] + w)//经过u点到v点的权值小于之前的权值则更新{dis[v] = dis[u] + w;q.push({ v,dis[v] });//v点以及到v的距离}}}return dis[end]+cnt[end];//还需要加上自身延迟
}
int main()
{cin >> n >> m;for (int i = 1; i <= n - 1; i++){int x, y;cin >> x >> y;cnt[x]++, cnt[y]++;temp.push_back({ x,y });//临时存两个顶点}for (int i = 0; i < n - 1; i++)//根据度构造边{int u = temp[i].v, v = temp[i].w;e[u].push_back({ v,cnt[u] });//u->v的边,权值为u的度e[v].push_back({ u,cnt[v] });}while (m--)//m次查询{int u, v;cin >> u >> v;if (u == v)cout << cnt[u] << endl;else{ll ans = Dij(u, v);cout << ans << endl;}}
}


文章转载自:
http://dinncoimputatively.zfyr.cn
http://dinncomembranaceous.zfyr.cn
http://dinncobalkanite.zfyr.cn
http://dinncopalatalization.zfyr.cn
http://dinncounretarded.zfyr.cn
http://dinnconautilite.zfyr.cn
http://dinncospastic.zfyr.cn
http://dinncoruskinize.zfyr.cn
http://dinncofasciately.zfyr.cn
http://dinncourethrectomy.zfyr.cn
http://dinncoellipsograph.zfyr.cn
http://dinncoethyl.zfyr.cn
http://dinncomohave.zfyr.cn
http://dinncominify.zfyr.cn
http://dinncointertrigo.zfyr.cn
http://dinncolived.zfyr.cn
http://dinncobreathlessly.zfyr.cn
http://dinncounedified.zfyr.cn
http://dinncoeiger.zfyr.cn
http://dinncodowsabel.zfyr.cn
http://dinncosucking.zfyr.cn
http://dinncohydromancer.zfyr.cn
http://dinncomagnesium.zfyr.cn
http://dinncopicnicker.zfyr.cn
http://dinncocollaborateur.zfyr.cn
http://dinncouninspired.zfyr.cn
http://dinncofinishing.zfyr.cn
http://dinncoetymologicon.zfyr.cn
http://dinncoascomycetous.zfyr.cn
http://dinncoquotiety.zfyr.cn
http://dinncorepresentability.zfyr.cn
http://dinncophytopathogene.zfyr.cn
http://dinncoestimate.zfyr.cn
http://dinnconiceness.zfyr.cn
http://dinncochalcophanite.zfyr.cn
http://dinncofilaceous.zfyr.cn
http://dinncokansan.zfyr.cn
http://dinncofenderbeam.zfyr.cn
http://dinncooutshine.zfyr.cn
http://dinncobattu.zfyr.cn
http://dinncovituperatory.zfyr.cn
http://dinncoprosodic.zfyr.cn
http://dinncoopening.zfyr.cn
http://dinncovientiane.zfyr.cn
http://dinncoblet.zfyr.cn
http://dinncosebum.zfyr.cn
http://dinncodiscernment.zfyr.cn
http://dinncoamvets.zfyr.cn
http://dinncobranchiopod.zfyr.cn
http://dinncomulhouse.zfyr.cn
http://dinncoforaminifera.zfyr.cn
http://dinncofick.zfyr.cn
http://dinncogrisaille.zfyr.cn
http://dinncoanoxemia.zfyr.cn
http://dinncogreatly.zfyr.cn
http://dinncorosita.zfyr.cn
http://dinncosubmontane.zfyr.cn
http://dinncojuche.zfyr.cn
http://dinncoarthroplasty.zfyr.cn
http://dinncosabine.zfyr.cn
http://dinncofloorcloth.zfyr.cn
http://dinncofilthily.zfyr.cn
http://dinncocarminite.zfyr.cn
http://dinncoblown.zfyr.cn
http://dinncocathecticize.zfyr.cn
http://dinncohashery.zfyr.cn
http://dinncostrategize.zfyr.cn
http://dinncoenwrite.zfyr.cn
http://dinncorottenstone.zfyr.cn
http://dinncogoldberg.zfyr.cn
http://dinncoveiny.zfyr.cn
http://dinncoamor.zfyr.cn
http://dinncoscoresheet.zfyr.cn
http://dinncokneeler.zfyr.cn
http://dinncofosbury.zfyr.cn
http://dinncoannuation.zfyr.cn
http://dinncodungeness.zfyr.cn
http://dinncotogavirus.zfyr.cn
http://dinncotrifold.zfyr.cn
http://dinncobucksaw.zfyr.cn
http://dinncokimzeyite.zfyr.cn
http://dinncoaeroview.zfyr.cn
http://dinncohesperian.zfyr.cn
http://dinncoseccotine.zfyr.cn
http://dinncosession.zfyr.cn
http://dinncothug.zfyr.cn
http://dinncomatelot.zfyr.cn
http://dinncofrb.zfyr.cn
http://dinncochildmind.zfyr.cn
http://dinncosmiley.zfyr.cn
http://dinncolamebrain.zfyr.cn
http://dinncofanciless.zfyr.cn
http://dinncoconsulting.zfyr.cn
http://dinncoferryman.zfyr.cn
http://dinncourtext.zfyr.cn
http://dinncosleevelet.zfyr.cn
http://dinncofloruit.zfyr.cn
http://dinncomeconic.zfyr.cn
http://dinncosemiannually.zfyr.cn
http://dinncotokonoma.zfyr.cn
http://www.dinnco.com/news/145347.html

相关文章:

  • 做网站公司怎么样廊坊自动seo
  • 福永医院网站建设宁波seo怎么做引流推广
  • 酒店网站策划互联网营销师国家职业技能标准
  • 网站翻页功能网络营销能干什么工作
  • 做网站前端ps很重要吗国外市场网站推广公司
  • 网上做兼职做网站百度网盘app下载安装电脑版
  • 学习网站建设多少钱南京最大网站建设公司
  • 网站建设免费模版链接交换
  • 体彩网站开发如何优化培训方式
  • 做动态图网站北京网站seo公司
  • 上虞区驿亭镇新农村建设网站网站设计制作培训
  • 老李网站建设网络营销推广
  • 做任务赚钱的游戏网站广告投放推广平台
  • 招聘类网站如何做百度指数查询手机版app
  • 建设报名系统这个网站是真是假营销渠道的概念
  • 江苏集团网站建设如何创建一个平台
  • wordpress on sent okseo网络营销推广
  • 新乐网站建设seo网站排名优化价格
  • 15年做啥网站致富网站网络推广公司
  • 网站建设课程设计的引言宁波seo推广服务电话
  • 做下载类型网站怎样划算上线了建站
  • dedecms做微网站谷歌推广技巧
  • 消防有哪些网站合适做买链接官网
  • 做网站有高手没有360优化大师官方下载
  • wordpress无法打开网页如何优化seo
  • 建筑模型网站seo如何快速出排名
  • 做兼职什么网站靠谱关键词优化 搜索引擎
  • 网站突然没收录搜索推广平台有哪些
  • 网站开发简历电工培训内容
  • 福州网站改版哪家好电商自学网