gpt4 book ai didi

c# - 在单声道中编译时 C# List 的问题(与作业相关)

转载 作者:可可西里 更新时间:2023-11-01 09:15:11 26 4
gpt4 key购买 nike

我承认这是我的功课。任务说明说我必须编写一个程序来查找将由标准输入输入的图的拓扑顺序。然后我需要将其提交到教授的服务器上进行评分。

现在不是算法问题了。这更像是一个技术问题。在我的计算机中,我使用 .NET 编译器 (csc),而教授的评分机使用某种形式的单声道。

效果很好,直到评分员说我得到了 30/100。我的一个 friend 建议我使用评分员的“手动输入系统”,所以我开始,我让它为邻接列表创建了 100000 个列表的数组。

评分员在几秒钟后报告说我的程序崩溃了。

Stacktrace:

at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0x00004>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0xffffffff>
at System.Exception.ToString () <0x00026>
at (wrapper runtime-invoke) object.runtime_invoke_object__this__ (object,intptr,intptr,intptr) <0xffffffff>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0x00004>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0xffffffff>
at System.Exception.ToString () <0x00026>
at (wrapper runtime-invoke) object.runtime_invoke_object__this__ (object,intptr,intptr,intptr) <0xffffffff>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0x00004>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0xffffffff>
at System.Exception.ToString () <0x00026>
at (wrapper runtime-invoke) object.runtime_invoke_object__this__ (object,intptr,intptr,intptr) <0xffffffff>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0x00004>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0xffffffff>
at System.Exception.ToString () <0x00026>
at (wrapper runtime-invoke) object.runtime_invoke_object__this__ (object,intptr,intptr,intptr) <0xffffffff>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0x00004>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0xffffffff>
at System.Exception.ToString () <0x00026>
at (wrapper runtime-invoke) object.runtime_invoke_object__this__ (object,intptr,intptr,intptr) <0xffffffff>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0x00004>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0xffffffff>
at System.Exception.ToString () <0x00026>
at (wrapper runtime-invoke) object.runtime_invoke

这对我来说有点奇怪和不安,但我还没有找到答案。同样,该程序在我的 PC 上运行得非常好。

这是我的程序部分:

using System;
using System.Collections;
using System.Collections.Generic;

class topo{
public static void Main(){
string[] ST = Console.ReadLine().Split(' ');
int N=Convert.ToInt32(ST[0]), M=Convert.ToInt32(ST[1]);
int[] ins = new int[N]; //node's total in-degrees
List<int>[] E = new List<int>[N];

for(int n=0;n<N;n++)
E[n] = new List<int>();

for(int m=0;m<M;m++){
ST = Console.ReadLine().Split(' ');
int u = Convert.ToInt32(ST[0]);
int v = Convert.ToInt32(ST[1]);
E[u-1].Add(v-1);
ins[v-1]++;
}

Queue S = new Queue();
List<int> L = new List<int>(); //result list

for(int n=0;n<N;n++){
//add stranded nodes directly and don't process it
if(ins[n]==0 && E[n].Count==0)
L.Add(n);

//put into queue
else if(ins[n]==0)
S.Enqueue(n);
}

while(S.Count>0){
int n = (int) S.Dequeue();
L.Add(n);
foreach(int m in E[n])
if(--ins[m]==0)
S.Enqueue(m);
}

foreach(int n in L)
Console.WriteLine(n+1);

}

}

非常感谢您,我感谢您的每一个回复。

编辑:我再次查看了评分员的输出,看看是否漏掉了什么,确实漏掉了。它说“syscal: 2”,但我所知道的是“程序没有正常退出。”

编辑 #2:我尝试让程序尝试制作各种大小的列表数组,范围从 5000、10000 等,在 40000 之后,“手动输入系统”说程序得到了一个系统.OutOfMemoryException。通过进一步查看允许学生进入的评分器的各个部分,教授似乎错误地配置了他的评分参数,并且给我们的内存比宣布的要少。 (他说的是“32MB”,但是程序在16MB左右就崩溃了)

我已将错误报告给他,他(现在)正在调查。

最佳答案

如果 uv 的值小于 1,则以下代码将失败。

for(int m=0;m<M;m++){
ST = Console.ReadLine().Split(' ');
int u = Convert.ToInt32(ST[0]);
int v = Convert.ToInt32(ST[1]);
E[u-1].Add(v-1);
ins[v-1]++;
}

因为 u-1v-1 将为负数,这将引发异常。

关于c# - 在单声道中编译时 C# List 的问题(与作业相关),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5284218/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com