c#写出的spfa
来源:互联网 发布:unsw moodle 网络 编辑:程序博客网 时间:2024/06/05 02:00
C#自己(似乎)是不内置队列的,所以手动实现了一个简易的队列。
手写scanf,但是并不会实现清屏操作,所以输入时很鬼畜……
就是这样了。
#region Using directivesusing System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using static System.Console;#endregionnamespace ConsoleApplication1{ class Queue { protected static int[] num = new int[99999]; protected int f; protected int b; public void clear() { for(int i=0;i<=99998;i++) { num[i] = 0; } f = 0; b = 0; } public void push(int n) { num[f] = n; f++; if (f == 99998) f = 0; } public int pop() { int k = b; b++; if (b == 99998) b = 0; return num[k]; } public bool empty() { return (f == b); } }; struct Edge { public int ff; public int tt; public int dd; public int nxt; }; class Program { public static int[] dist = new int[6300]; public static bool[] passby = new bool[6300]; public static Edge[] edge = new Edge[20000]; public static int T, C, Ts, Te; public static int tot = 0; public static int[] head = new int[6300]; static void print(int a) { WriteLine($"{dist[a]}"); } static void add(int f, int t, int d) { edge[++tot].ff = f; edge[tot].tt = t; edge[tot].dd = d; edge[tot].nxt = head[f]; head[f] = tot; } static void scanf(int a) { int i = 0; a = 0; char c = '0'; while(c != '\n' && c != ' ') { i++; a *= 10; a += (c - '0'); c = ReadKey().KeyChar; } while(i!=0) { i--; WriteLine("6666666666666"); } } static void spfa() { Queue q = new Queue(); q.clear(); dist[Ts] = 0; passby[Ts] = true; q.push(Ts); while(!q.empty()) { int x = q.pop(); passby[x] = false; for(int i=head[x];i!=0;i=edge[i].nxt) { Edge e = edge[i]; if(dist[e.tt]>dist[x]+e.dd) { dist[e.tt] = dist[x] + e.dd; if(!passby[e.tt]) { q.push(e.tt); passby[e.tt] = true; } } } } } static void Main(string[] args) { T = 0; C = 0; Ts = 0; Te = 0; scanf(T); scanf(C); scanf(Ts); scanf(Te); for(int i=1;i<=C;i++) { int f = 0, t = 0, d = 0; scanf(f); scanf(t); scanf(d); add(f, t, d); add(t, f, d); } for(int i=0;i<=T;i++) { dist[i] = 0x7fffffff; passby[i] = false; } spfa(); print(Te); ReadKey(); } }}
0 0
- c#写出的spfa
- C++ 语言 写出类似C#的面向对象的方法
- 晕了,C#莫名其妙的写出来一个奇怪代码。。。。。。
- C#将内容写出到Excel的表格中
- 关于c#文件流与二进制的读入写出(一)
- 关于c#文件流与二进制的读入写出(二)
- 关于C#文件流与二进制的读入写出(三)
- 使用C#写出一个简单的记事本程序
- C#写出的软件使用Tab按钮时的选择控件的顺序
- 值类型和引用类型的区别?写出C#的样例代码。
- 写出程序的关键
- 写出好的程序
- C#初学者—— 终于写出了自己第一个比较满意的程序
- C#请写出代码判断一个整数是不是2的幂次方
- C#通过NCO 调用RFC(写出)
- c# DataSet写出XML,返回为文本
- SPFA的堆栈实现
- SPFA的两个优化
- android开发之Activity详解
- GDOI 2017划水记
- Maven详解
- double类型转换为字符串, 整型转换为字符串
- Java接口_interface_implements
- c#写出的spfa
- CCF NOI1089 高精度运算
- Day 3 网络流
- Spring和MyBatis环境整合
- C++结构体和共用体
- 学习淘淘商城第四十三课(实现从数据库导入数据到索引库)
- Docker Makefile文件结构
- 日历程序
- hibernate里面的一对多和多对一映射