Buffer.SetByte()
解决方案 »
- C# 类型问题
- C# 写一个程序 运行后可以生成自己的dll文件.
- 100分,急 一个盘点机器的接口,如何申明这个 dll中的 NLS_CopyFileEx 函数呢? 对应的参数类型如何处理呢?
- 为了满足网络内部访问图片,把图片保存到了数据库中,可是出了一个异常,不会调了。
- 求救:Access is denied!该如何解决?
- WPF,请问设置TabItem的间距
- 多语言混合编程:用VC.NET或VB.NET写的类,如何在C#.NET中使用?
- 如何操作远程文件?
- 多线程调用Control.Invoke的问题
- window form中的datagrid有分页功能吗?如果要分页该怎么办??
- winform Resources.resx Settings.settings app.config
- C#写计算器的时候,怎么把运算显示出来。
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;
}
}
}
}
}
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;
}
}这是我能想到的方法,或者你会有更好的方法,不过到时,请告诉我。
参考: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