首页 > 编程语言 >C#城市线路图的纯算法以及附带求极权值

C#城市线路图的纯算法以及附带求极权值

时间:2023-07-19 23:47:43浏览次数:52  
标签:极权 string C# 线路图 Add backlist new null arry

 常用的数据结构写出来 纯属于算法 性方面还有待提高 时间复杂度最坏情况下O(2^n)  最优:O(n^2)

线路图为双向 带有权值  比如A-B距离是5000km 那么B-A有可能不是5000km 所以我在LoadData方法时候没做交换变量直接存放在集合里面

以起点递归查找下一连接点并返回当作起点节点查找      代码虽然有些乱 本想调整 !


  static List<string[]> maindata = null;
        static int isend = 1;
        static List<string> fresult = new List<string>();

        static void Main(string[] args)
        {
            string begin = "重庆";
            string end = "厦门";
            LoadData();
            Program pl = new Program();
            List<string> beginlist = new List<string>();
            beginlist.Add(begin);
            pl.GetF(beginlist);

            foreach (string a in fresult)
                Console.WriteLine(a);
            Console.WriteLine(fresult.Count);
            //main data end

            List<string> searchlist = new List<string>();
            string temp = "";
            foreach (string f in fresult)
            {
                if (f.IndexOf(end) > -1)
                {
                    temp = f.Substring(0, f.LastIndexOf(end) + end.Length);
                    if (searchlist.Contains(temp) == false)
                        searchlist.Add(temp);
                }
            }
            Console.WriteLine(begin + "------------->" + end + ":");
            foreach (string a in searchlist)
                Console.WriteLine(a);
            Console.WriteLine(searchlist.Count);
            //search data   A to B

            string a1 = "权最大为:" + GetMaxQuk(searchlist);
            Console.WriteLine(a1);
            a1 = "权最小为:" + GetMinQuk(searchlist);
            Console.WriteLine(a1);

            Console.ReadKey();
        }

  取最大的权值数据
        private static string GetMaxQuk(List<string> nage) 
        {
            string resultsrt = "";

            string[] nagearry = null;
            int val, maxval = 0;
            for (int s = 0; s < nage.Count; s++)
            {
                nagearry = nage[s].Split('-');//s个数组
                val = GetVal(nagearry);
                if (val > maxval)
                {
                    maxval = val;
                    resultsrt = nage[s] + ":" + val;
                }
                nagearry = null;
            }
            return resultsrt;
        }

取最小的权值数据
        private static string GetMinQuk(List<string> nage)
        {
            string resultsrt = "";
            string[] nagearry = null;
            int val, minval = int.MaxValue;
            for (int s = 0; s < nage.Count; s++)
            {
                nagearry = nage[s].Split('-');//s个数组
                val = GetVal(nagearry);
                if (val < minval)
                {
                    minval = val;
                    resultsrt = nage[s] + ":" + val;
                }
                nagearry = null;
            }
            return resultsrt;
        }

  具体取权值的方法
        private static int GetVal(string[] findarry)
        {
            int val = 0;
            for (int ss = 0; ss < findarry.Length - 1; ss = ss + 1)
            {
                foreach (string[] aa in maindata)
                {
                    if (aa[0] == findarry[ss] && aa[1] == findarry[ss + 1])
                    {
                        val += Convert.ToInt32(aa[2]);
                        break;
                    }
                }
            }
            return val;
        }

        List<string> GetF(List<string> beginlist)
        {
           //此处省略几十行代码 需要完整代码请联系an
            if (isend == 0)
                return GetF(returnlist);
            else
                return null;
        }

加载绑定数据
       static void LoadData()
       {
            List<string[]> backlist = null;
            string[] arry = null;

            backlist = new List<string[]>();

            arry = new string[3];
            arry[0] = "重庆";
            arry[1] = "北京";
            arry[2] = "3000";
            backlist.Add(arry);
            arry = null;
            arry = new string[3];
            arry[0] = "重庆";
            arry[1] = "广州";
            arry[2] = "2500";
            backlist.Add(arry);
            arry = null;

            arry = new string[3];
            arry[0] = "北京";
            arry[1] = "重庆";
            arry[2] = "3000";
            backlist.Add(arry);
            arry = null;
            arry = new string[3];
            arry[0] = "北京";
            arry[1] = "广州";
            arry[2] = "3100";
            backlist.Add(arry);
            arry = null;
            arry = new string[3];
            arry[0] = "北京";
            arry[1] = "长沙";
            arry[2] = "2800";
            backlist.Add(arry);
            arry = null;

            arry = new string[3];
            arry[0] = "长沙";
            arry[1] = "北京";
            arry[2] = "2800";
            backlist.Add(arry);
            arry = null;
            arry = new string[3];
            arry[0] = "长沙";
            arry[1] = "广州";
            arry[2] = "1500";
            backlist.Add(arry);
            arry = null;
            arry = new string[3];
            arry[0] = "长沙";
            arry[1] = "厦门";
            arry[2] = "800";
            backlist.Add(arry);
            arry = null;

            arry = new string[3];
            arry[0] = "广州";
            arry[1] = "重庆";
            arry[2] = "2500";
            backlist.Add(arry);
            arry = null;
            arry = new string[3];
            arry[0] = "广州";
            arry[1] = "北京";
            arry[2] = "3100";
            backlist.Add(arry);
            arry = null;
            arry = new string[3];
            arry[0] = "广州";
            arry[1] = "长沙";
            arry[2] = "1500";
            backlist.Add(arry);
            arry = null;
            maindata = backlist;

 
            arry = new string[3];
            arry[0] = "厦门";
            arry[1] = "长沙";
            arry[2] = "800";
            backlist.Add(arry);
            arry = null;
            arry = new string[3];
            arry[0] = "厦门";
            arry[1] = "广州";
            arry[2] = "500";
            backlist.Add(arry);
            arry = null;
            arry = new string[3];
            arry[0] = "广州";
            arry[1] = "厦门";
            arry[2] = "500";
            backlist.Add(arry);
            arry = null;

 
            arry = new string[3];
            arry[0] = "广州";
            arry[1] = "云南";
            arry[2] = "3200";
            backlist.Add(arry);
            arry = null;
            arry = new string[3];
            arry[0] = "云南";
            arry[1] = "广州";
            arry[2] = "3200";
            backlist.Add(arry);
            arry = null;
            arry = new string[3];
            arry[0] = "云南";
            arry[1] = "长沙";
            arry[2] = "3500";
            backlist.Add(arry);
            arry = null;
            arry = new string[3];
            arry[0] = "长沙";
            arry[1] = "云南";
            arry[2] = "3500";
            backlist.Add(arry);
            arry = null;
            arry = new string[3];
            arry[0] = "云南";
            arry[1] = "厦门";
            arry[2] = "5400";
            backlist.Add(arry);
            arry = null;
            arry = new string[3];
            arry[0] = "厦门";
            arry[1] = "云南";
            arry[2] = "5400";
            backlist.Add(arry);
            arry = null;

        }
 
完整代码信息异步同城信息港

标签:极权,string,C#,线路图,Add,backlist,new,null,arry
From: https://www.cnblogs.com/yeci/p/17567092.html

相关文章

  • 介绍ChatGPT付费创作绘画系统 (WEB端+ H5端 + 小程序端)
     ChatGPT付费创作系统V2.1.0提供最新的对应版本小程序端,上一版本增加了PC端绘画功能,绘画功能采用其他绘画接口-意间AI,本版新增了百度文心一言接口。演示地址:www.runruncode.com/ai/19468.html后台一些小细节的优化及一些小BUG的处理,前端进行了些小细节优化,针对上几版大家非......
  • 大白话讲讲 Go 语言的 sync.Map(一)
    阅读本文大约需要4.25分钟。程序是枯燥乏味的。在讲sync.Map之前,我们先说说什么是map(映射)。我们每个人都有身份证号码,如果我需要从身份证号码查到对应的姓名,用map存储是非常合适的。map[000...001]=张三map[000...002]=李四...map[999...993]=钱五身份证号......
  • Docker大会的新福利:LinuxKit 和 Moby 开源项目
    在一年一度的DockerCon大会上,来自全球各地的5000名参与者,济济一堂,于奥斯丁会议中心,共同见证Docker的发展,探讨容器技术的落地。 Docker创办人暨技术长SolomonHykes认为,今年容器将成为主流,将散布伺服器、资料中心、云端、桌面、IoT与行动等运算装置,或金融、医疗保键......
  • Docker大会的新福利:LinuxKit 和 Moby 开源项目
    在一年一度的DockerCon大会上,来自全球各地的5000名参与者,济济一堂,于奥斯丁会议中心,共同见证Docker的发展,探讨容器技术的落地。 Docker创办人暨技术长SolomonHykes认为,今年容器将成为主流,将散布伺服器、资料中心、云端、桌面、IoT与行动等运算装置,或金融、医疗保键......
  • Docker大会的新福利:LinuxKit 和 Moby 开源项目
    在一年一度的DockerCon大会上,来自全球各地的5000名参与者,济济一堂,于奥斯丁会议中心,共同见证Docker的发展,探讨容器技术的落地。 Docker创办人暨技术长SolomonHykes认为,今年容器将成为主流,将散布伺服器、资料中心、云端、桌面、IoT与行动等运算装置,或金融、医疗保键......
  • c#根据城市名称获取相关信息
    ​ 实现:得到真实IP以及所在地详细信息/通过IP得到IP所在地省市/获取HTML源码信息,感兴趣的朋友不妨了解一下,或许对你巩固所学知识有所帮助///<summary> ///得到真实IP以及所在地详细信息(Porschev) ///</summary> ///<returns></returns> publicstringGetIpDetails......
  • Educational Codeforces Round 151
    AB略C(简)将密码\(P\)与\(S\)进行匹配,按顺序决定\(P_i\),为了避免\(P\)成为\(S\)的子串,每次贪心地选择当前匹配位置最靠后的。若出现匹配不上则“YES”。D有点意思。从基础的情况入手:设\(\{s_i\}\)为\(\{a_i\}\)的前缀和,弄出\(\{s_i\}\)的图像,让我们考虑第一个......
  • MATLAB用GARCH-EVT-Copula极值理论模型VaR预测分析股票投资组合|附代码数据
    全文链接:http://tecdat.cn/?p=30426最近我们被客户要求撰写关于GARCH-EVT-Copula的研究报告,包括一些图形和统计输出。对VaR计算方法的改进,以更好的度量开放式基金的风险。本项目把基金所持股票看成是一个投资组合,引入Copula来描述多只股票间的非线性相关性,构建多元GARCH-EVT-Cop......
  • 多线程:C语言 - 简易线程池的原理和实现
    目录线程循环处理任务,线程不退出1.存储任务--循环读取任务2.函数回调--函数退出,线程不退出本质是事件驱动,是生产者消费者模型1.工作线程--线程池的池化单元,任务的消费者2.线程池持有者--提供多任务,任务的生产者存储任务的数据结构1.任务(task_t)2.任务队列/阻塞队列(task_q......
  • 初识C语言——3
    循环1、while——while(表达式)     循环语句;2、for(表达式1;表达式2;表达式3)      循环语句;for循环语句中三个表达式都可以省略——即判断省略处,恒为真。for(i=2;i=0;i++)//——表达式2,将0赋值给i;0为假,则不满足表达式2;不进入循环。3、do   循环语句;while(......