Posts Tagged 'cshap'

3部电梯简单算法

Posted by Danfi on 2010-05-19 2 条评论

毕业设计要没时间了,只能弄个简单的算法填充下了,把情况分为8种就是2的三次方,每部电梯有运行停止两种情况。

空闲停止的电梯最先被考虑,以0表示停止,1表示运行中。就分为000,001,010,011,100,101,110,111八种

情况。000的时候计算3部电梯与目的层的距离,并取最小值,如果3部电梯距离相同,取中间电梯,如果两部电梯同时为

最小则取其中一部,以左、中优先考虑。001时在左中之间取最小值,相同则取中间。010时取左右之间的最小值,相同

则取左边。011时取左边。100时在中右之间取最小值,相同则取中间。101时取中间。110时取右边。111时仍取最小值,

当在同一方向时取三个之中的最小值,在其他情况下优先取与目的同方向的电梯,优先顺序为中左右。以上算法排除底层

和最高层,其算法另写。当然还有很多逻辑可能是错误的。

C#显本机IP信息和服务器信息

Posted by Danfi on 2010-03-27 添加评论
  1. namespace IPExample
  2. {
  3.     public partial class Form1 : Form
  4.     {
  5.         public Form1()
  6.         {
  7.             InitializeComponent();
  8.         }
  9.  
  10.         private void button1_Click(object sender, EventArgs e)
  11.         {
  12.             listBox1.Items.Clear();
  13.             string name = Dns.GetHostName();
  14.             listBox1.Items.Add("本机主机名:" + name);
  15.             IPHostEntry me = Dns.GetHostEntry(name);
  16.             listBox1.Items.Add("本机所有IP地址:");
  17.             foreach (IPAddress ip in me.AddressList)
  18.             {
  19.                 listBox1.Items.Add(ip);
  20.             }
  21.             IPAddress localip = IPAddress.Parse("127.0.0.1");
  22.             IPEndPoint iep = new IPEndPoint(localip, 80);
  23.             listBox1.Items.Add("The IPEndPoint is: " + iep.ToString());
  24.             listBox1.Items.Add("The Address is: " + iep.Address);
  25.             listBox1.Items.Add("The AddressFamily is: " + iep.AddressFamily);
  26.             listBox1.Items.Add("The max port number is: " + IPEndPoint.MaxPort);
  27.             listBox1.Items.Add("The min port number is: " + IPEndPoint.MinPort);
  28.  
  29.         }
  30.  
  31.         private void button2_Click(object sender, EventArgs e)
  32.         {
  33.             listBox1.Items.Clear();
  34.             IPHostEntry remoteHost = Dns.GetHostEntry("www.cctv.com");
  35.             IPAddress[] remoteIP = remoteHost.AddressList;
  36.             listBox1.Items.Add("中央电视台:");
  37.             foreach (IPAddress ip in remoteIP)
  38.             {
  39.                 IPEndPoint iep = new IPEndPoint(ip, 80);
  40.                 listBox1.Items.Add(iep);
  41.             }
  42.  
  43.         }
  44.     }
  45. }