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

建一个类似淘宝的网站需要多少钱简易网站制作

建一个类似淘宝的网站需要多少钱,简易网站制作,个人备案的网站可以做淘宝客吗,网站免费建立链接:P3385 【模板】负环 - 洛谷 题目: 思路: 考察 Bellman-Ford 或 SPFA 本题是一个板子题,也是学到了 Bellman-Ford 和 SPFA Bellman-Ford 算法的主要思想其实类似迪杰斯特拉,我们暴力枚举每一个点的每一条边&…

链接:P3385 【模板】负环 - 洛谷

题目:

思路:

考察 Bellman-Ford 或 SPFA

本题是一个板子题,也是学到了 Bellman-Ford 和 SPFA

Bellman-Ford 算法的主要思想其实类似迪杰斯特拉,我们暴力枚举每一个点的每一条边,如果能更新最小距离,那么就替换,同时标记该次我们进行了松弛操作,通常情况下 n-1 次松弛操作后我们就能找到最短路了,但是由于可能存在负环,因此我们要注意多判断一次

负环顾名思义就是权值为负的环,既然它为负,那么我们就可以走无数次使得这个环的权值无限小

SPFA 则是利用队列进行了优化,也类似迪杰斯特拉的队列优化,这次我们不再暴力枚举每个点,而是枚举队列中可能更新的点,那么什么情况下可能更新呢?显然是上次更新过的点下次才可能继续更新,因此我们就要提供三个新东西,一个是判断该点是否已经在队列中,一个是判断该点入队了几次,还一个就是队列了

下面提供两个算法的代码

代码:

#include <iostream>
#include <algorithm>
#include<cstring>
#include <iomanip>
#include<cctype>
#include<string>
#include <set>
#include <vector>
#include <cmath>
#include <queue>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <utility>
#include <array>
#include <tuple>
using namespace std;
#define int long long
#define yes cout << "YES" << endl
#define no cout << "NO" << endlvoid solve()
{int n, m;cin >> n >> m;vector<vector<pair<int,int>>> g(n + 1);for (int i = 0; i < m; i++){int u, v, w;cin >> u >> v >> w;if (w >= 0){g[u].push_back({ v,w });g[v].push_back({ u,w });}else{g[u].push_back({ v,w });}}int flag = 0;vector<int> dis(n + 1, 1e18);dis[1] = 0;for (int i = 1; i <= n; i++){flag = 0;for (int i = 1; i <= n; i++){if (dis[i] == 1e18) continue;for (auto &son : g[i]){if (dis[son.first] > dis[i] + son.second){dis[son.first] = dis[i] + son.second;flag = 1;}}}}flag ? yes : no;
}
signed main()
{//cin.tie(0)->sync_with_stdio(false);int t = 1;cin >> t;while (t--){solve();}return 0;
}
#include <iostream>
#include <algorithm>
#include<cstring>
#include <iomanip>
#include<cctype>
#include<string>
#include <set>
#include <vector>
#include <cmath>
#include <queue>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <utility>
#include <array>
#include <tuple>
using namespace std;
#define int long long
#define yes cout << "YES" << endl
#define no cout << "NO" << endlvoid solve()
{int n, m;cin >> n >> m;vector<vector<pair<int,int>>> g(n + 1);for (int i = 0; i < m; i++){int u, v, w;cin >> u >> v >> w;if (w >= 0){g[u].push_back({ v,w });g[v].push_back({ u,w });}else{g[u].push_back({ v,w });}}vector<int> dis(n + 1, 1e18);vector<int> vis(n + 1, 0);vector<int> cnt(n + 1, 0);queue<int> q;q.push(1);dis[1] = 0;vis[1] = 1;while (!q.empty()){auto t = q.front();q.pop();vis[t] = 0;for (auto son : g[t]){if (dis[son.first] > dis[t] + son.second){dis[son.first] = dis[t] + son.second;cnt[son.first] = cnt[t] + 1;if (cnt[son.first] >= n){yes;return;}if (!vis[son.first])q.push(son.first), vis[son.first] = 1;}}}no;
}
signed main()
{//cin.tie(0)->sync_with_stdio(false);int t = 1;cin >> t;while (t--){solve();}return 0;
}

 

http://www.dtcms.com/wzjs/274655.html

相关文章:

  • 网站创建流程最近的头条新闻
  • 山西建设厅八大员查询网站推广普通话手抄报简单又好看内容
  • 专业的聊城做网站费用腾讯推广一次广告多少钱
  • 网站的建设流程图张掖seo
  • wordpress给用户自动注册东莞优化seo
  • 所有搜索引擎蜘蛛不来网站了百度广告优化
  • 做5g网站空间容量要多少钱今日特大军事新闻
  • dede手机网站搜狗站长推送工具
  • 开发网站合作协议seo型网站
  • 好点的开发网站的公司视频号推广
  • 企业网站建设排名开发网站建设公司
  • 网站联系我们 怎么做地图怎么上百度搜索
  • 网站后台不显示文章内容厦门seo培训学校
  • 杭州做网站五广告营销顾问
  • 北大青鸟的网站建设课程多少钱免费永久个人域名注册
  • 寻找郑州网站建设公司百度网站提交了多久收录
  • 平板电脑网站模板东莞百度推广排名
  • 做的网站没有注册谷歌搜索引擎营销
  • 最专业的网站开发公司哪家最专业东营seo
  • 网站建设带服务器b站引流推广网站
  • 产权交易中心网站建设的原因中国最厉害的营销策划公司
  • 网站更换域名 seo聊城网站开发
  • 外贸精品网站建设关键词优化公司费用多少
  • 怎么建php网站公司网站建站要多少钱
  • 泉州网站建设测试如何发布自己的html网站
  • 天津seo方案安卓优化大师官网
  • 科技感的网站站长工具seo综合查询怎么用
  • 十里堡网站建设关键字挖掘机爱站网
  • 网站开发公司哪家最专业小程序推广平台
  • 上海做网站公司seo外链