【发布时间】:2016-04-10 21:27:24
【问题描述】:
我在大学项目中遇到了麻烦。该项目需要使用 c# 作为编程语言来完成,并以 Windows 窗体之类的方式制作。 程序执行。我知道它有缺陷,但至少我想知道如何解决这个错误:http://postimg.org/image/gwuzmyc73/。 对于这个问题,我需要使用 Divide et Impera 折叠一个向量。 我需要从键盘 n 中插入一个数字,生成的向量就像 a=(1,2,3,4,5,6,7),最终元素是 1,3,5,7。 问题听起来像: n 个元素的向量。如果 n 是奇数,我们通过重叠 2 个半部分来定义它的折叠。再次折叠 2 个半部分,直到 de 子向量达到 1 个元素。利用 Divide et Impera。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Plierea_Vectorilor
{
public partial class Form1 : Form
{
public int n;
public int i;
public int[] efinal = new int[50];
public string m = new string(new char[50]);
public int Ls, Ld;
public char[] aux = new char[50];
public Form1()
{
InitializeComponent();
}
public void Pliaza(int p,int q)
{
if (p == q)
{
efinal[p] = 1;
}
else
{
if ((q - p + 1) % 2 != 0)
{
Ls = (p + q) / 2 - 1;
}
else
{
Ls = (p + q) / 2;
}
Ld = (p + q) / 2 + 1;
}
Pliaza(p, Ls);
Pliaza(Ld, q);
/*
string ss = Ls.ToString();
string sd = Ld.ToString();
for (i = p; i <= Ls; i++)
{
aux[0] = 'S';
string.Concat(aux, ss);
string.Concat(aux, " ");
string m = aux.ToString();
string.Concat(aux, m[i]);
}
for ( i = Ld; i <= q; i++)
{
aux[0] = 'D';
string.Concat(aux,Ld);
string.Concat(aux, " ");
string m = aux.ToString();
string.Concat(aux, m[i]);
}
*/
}
private void button1_Click(object sender, EventArgs e)
{
Pliaza(1, n);
for (i = 1; i <= n; i++)
{
if (efinal[i]!=0)
{
label2.Text = Convert.ToString(i);
}
}
}
private void label2_Click(object sender, EventArgs e)
{
}
}
}
【问题讨论】:
标签: c# windows forms vector folding