Buffer.SetByte()

解决方案 »

  1.   

    亲 那请问这段代码应该怎么修改呢using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;namespace 最大流
    {
        class Program
        {
            static void Main(string[] args)
            {
                private const int maxN =201;            private static int[,] edge = new int[maxN, maxN];
                private bool[] visited = new bool[maxN];
                private int[] father = new int[maxN];
                private int N; //边数,顶点数
                private int M;
                private int ans; //结果
                private void Ford_Fulkerson()
                {            while(1)
                {
                //一次大循环,找到一条可能的增广路径
                Queue<int> q = new Queue<int>();
                //C++ TO C# CONVERTER TODO TASK: The memory management function 'memset' has no equivalent in C#:
                memset(visited, 0, sizeof(visited));
                //C++ TO C# CONVERTER TODO TASK: The memory management function 'memset' has no equivalent in C#:
                memset(father, -1, sizeof(father));
                int now;
                visited[0] = true;
                q.Enqueue(0);
                while(!q.Count == 0) //广度优先
                {
                now = q.Peek();
                q.Dequeue();
                if(now == M-1)
                break;
                for(int i = 0; i < M; i++)
                {
                //每次父亲节点都要更新,权值减为0的边就不算了.
                if(edge[now, i] && !visited[i])
                {
                father[i] = now;
                visited[i] = true;
                q.Enqueue(i);
                }
                }
                }
                //可能的增广路不存在了
                if(!visited[M-1])
                break;
                int u;
                int min = 0xFFFF;
                for(u = M-1; u; u = father[u]) //找出权值最小的边
                {
                if(edge[father[u], u] < min)
                min = edge[father[u], u];
                }
                //减去最小权值
                for(u = M-1; u; u = father[u])
                {
                //前向弧减去
                edge[father[u], u] -= min;
                //后向弧加上
                //存在圆环,这句话关键
                edge[u, father[u]] += min;
                }
                //当前增广路径增加的流
                ans += min;
                }
                }            private static int Main()
                {
                int s;
                int e;
                int w;
                while((N = SimulateCin.ReadToWhiteSpace(true)).Length > 0 && (M = SimulateCin.ReadToWhiteSpace(true)).Length > 0)
                {
                ans = 0;
                //C++ TO C# CONVERTER TODO TASK: The memory management function 'memset' has no equivalent in C#:
                memset(edge, 0, sizeof(edge));
                for(int i = 0; i<N; i++)
                {
                s = int.Parse(ReadToWhiteSpace(true));
                e = SimulateCin.ReadToWhiteSpace(true);
                w = SimulateCin.ReadToWhiteSpace(true);
                edge[s-1, e-1] += w;
                }
                Ford_Fulkerson();
                Console.Write(ans);
                Console.Write("\n");
                }
                return 0;
                }
               
                internal static class SimulateCin
                {
                private static bool goodlastread = false;
                internal static bool LastReadWasGood
                {
                get
                {
                return goodlastread;
                }
                }            internal static string ReadToWhiteSpace(bool skipleadingwhitespace)
                {
                string input = "";
                char nextchar;
                if (skipleadingwhitespace)
                {
                while (char.IsWhiteSpace(nextchar = (char)Console.Read()))
                {
                }
                input += nextchar;
                }
                while ( ! char.IsWhiteSpace(nextchar = (char)Console.Read()))
                {
                input += nextchar;
                }
                goodlastread = input.Length > 0;
                return input;
                }
                }
                    }
                }
    }
      

  2.   


     void memset(int[] dest, int c, int count)
            {
                for (int i = 0; i < dest.Length; i++)
                {
                    dest[i] = c;
                }
            }        void memset(bool[] dest, bool b, int count)
            {
                for (int i = 0; i < dest.Length; i++)
                {
                    dest[i] = b;
                }
            }这是我能想到的方法,或者你会有更好的方法,不过到时,请告诉我。
      

  3.   

    C#不需要memset,因为结构体或者数据初始化都会被自动填充0。
      

  4.   

        public static void SetByte(Array array,int index,byte value)
       参考:http://technet.microsoft.com/zh-cn/magazine/system.buffer.setbyte(VS.95).aspx
        Array.Clear(numbers1, 0, 50);
       参考:http://msdn.microsoft.com/zh-cn/library/system.array.clear.aspx