110,556
社区成员
发帖
与我相关
我的任务
分享
protected void Button1_Click(object sender, EventArgs e)
{
//X, X1, X2 总和 = 45 或者 44 可以 随即组合
//Y, Y1, Y2 随便正数
//这里A必须是取最大的,B取正数(不限大小), C要去最小的
for (int xx = 1; xx <= 45; xx++)
{
for (int xx1 = 1; xx1 <= 45; xx1++)
{
for (int xx2 = 1; xx2 <= 45; xx2++)
{
if (xx + xx1 + xx2 == 45)
{
setTow(xx, xx1, xx2);
}
}
}
}
Response.Write("X=" + temp[0].ToString() + "<br />");
Response.Write("X1=" + temp[1].ToString() + "<br />");
Response.Write("X2=" + temp[2].ToString() + "<br />");
Response.Write("Y=" + temp[3].ToString() + "<br />");
Response.Write("Y1=" + temp[4].ToString() + "<br />");
Response.Write("Y2=" + temp[5].ToString() + "<br />");
Response.Write("A=" + tempa.ToString() + "<br />");
Response.Write("B=" + tempb.ToString() + "<br />");
Response.Write("C=" + tempc.ToString() + "<br />");
}
double? tempa = null, tempb = null, tempc = null;
int[] temp=new int[6];
//函数
private void setTow(int x, int x1, int x2)
{
int loopValue = 100;//这是你可自行赋值
int z, z1, z2,w,w1,w2;
double a,b,c,sum;
for (int y = 1; y <= loopValue; y++)
{
for (int y1 = 1; y1 <= loopValue; y1++)
{
for (int y2 = 1; y2 <= loopValue; y2++)
{
z = x * y;
z1 = x1 * y1;
z2 = x2 * y2;
sum = Convert.ToDouble(z + z1 + z2) * 0.86;
w = y * 42;
w1 = y1 * 42;
w2 = y2 * 42;
a = Convert.ToDouble(w) - sum;
b = Convert.ToDouble(w1) - sum;
c = Convert.ToDouble(w2) - sum;
if (tempa == null)
{
tempa = a;
tempb = b;
tempc = c;
}
else
{
if (b > 0)//B取正数
{
if (a > tempa && c < tempc)//a取最大同时C要最小
{
tempa = a;
tempb = b;
tempc = c;
temp[0] = x;
temp[1] = x1;
temp[2] = x2;
temp[3] = y;
temp[4] = y1;
temp[5] = y2;
}
}
}
}
}
}
}