洛谷 T480715 true

a的真实值是a\div 10b的真是值是b \times 10,那么c的真是值便是10000-a-b

AC CODE:

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int main(){
	int a,b;
	cin>>a>>b;
	int true_a=a/10,true_b=b*10;
	int true_c=10000-true_a-true_b;
	cout<<true_a<<' '<<true_b<<' '<<true_c<<endl;
	return 0;
}

判断负环的经典算法是 Bellman-Ford 算法。该算法的主要思想是进行 n 次松弛操作,其中 n 为图中节点的数量。如果在第 n 次松弛操作后仍然存在可以被松弛的边,则说明图中存在负环。 在具体实现时,可以先将所有节点的距离初始化为正无穷大,起始节点的距离为 0。然后进行 n 次松弛操作,每次松弛操作都枚举所有边,如果该边的起点的距离加上边的权值小于终点的距离,则更新终点的距离。如果在第 n 次松弛操作后仍然存在可以被松弛的边,则说明图中存在负环。 具体代码实现可以参考以下代码: ```cpp #include <iostream> #include <vector> #include <queue> #include <cstring> using namespace std; const int INF = 0x3f3f3f3f; struct Edge { int to, weight; Edge(int _to, int _weight) : to(_to), weight(_weight) {} }; vector<Edge> edges[1000]; int dist[1000]; bool inQueue[1000]; bool bellmanFord(int start, int n) { memset(dist, INF, sizeof(dist)); dist[start] = 0; queue<int> q; for (int i = 1; i <= n; i++) { q.push(i); inQueue[i] = true; } while (!q.empty()) { int u = q.front(); q.pop(); inQueue[u] = false; for (int i = 0; i < edges[u].size(); i++) { int v = edges[u][i].to; int w = edges[u][i].weight; if (dist[u] != INF && dist[u] + w < dist[v]) { dist[v] = dist[u] + w; if (!inQueue[v]) { q.push(v); inQueue[v] = true; } if (dist[v] < 0) { return true; } } } } return false; } int main() { int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { int u, v, w; cin >> u >> v >> w; edges[u].push_back(Edge(v, w)); } if (bellmanFord(1, n)) { cout << "YES" << endl; } else { cout << "NO" << endl; } return 0; } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值