设为首页 加入收藏

TOP

均值不等式的简单探究(一)
2014-11-23 22:25:21 来源: 作者: 【 】 浏览:4
Tags:均值 不等式 简单 探究

\

\

//Copyright (c) LeafCore
#include
#include
#include

LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);
void draw(HDC);

char szClassName[ ] = "LeafCore";

int WINAPI WinMain(HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)

{
HWND hwnd;
MSG messages;
WNDCLASSEX wincl;

wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof (WNDCLASSEX);

wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);

if (!RegisterClassEx(&wincl))
return 0;

hwnd=CreateWindowEx(
0,
szClassName,
"LeafCore",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
1024,
768,
HWND_DESKTOP,
NULL,
hThisInstance,
NULL
);

ShowWindow(hwnd, nFunsterStil);

while(GetMessage(&messages, NULL, 0, 0)) {
TranslateMessage(&messages);
DispatchMessage(&messages);
}

return messages.wParam;
}

LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
switch (message) {
case WM_PAINT:
hdc=BeginPaint(hwnd, &ps);
HPEN green_pen=CreatePen(PS_SOLID, 1, RGB(0, 127, 0));
HPEN old_pen=(HPEN) SelectObject(hdc, green_pen);

draw(hdc);

SelectObject(hdc, old_pen);
DeleteObject(green_pen);
EndPaint(hwnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage (0);
break;
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}

return 0;
}

void draw(HDC hdc)
{
//q的数量
const int const_q=1000;
double q[const_q];
double x, y;
//q中的最大数
double greatest;
//q中的最小数
double least;

//初始化随机数产生器
srand(time(0));

//产生q
for (int i=0; i q[i]=rand()%300+100;
}

//找出q中的最大数和最小数
greatest=q[0];
least=q[0];
for (int i=1; i if (greatest greatest=q[i];
}
if (least>q[i]) {
least=q[i];
}
}

//画出代表最大数的直线
MoveToEx(hdc, -100*4+450, (int)-greatest+600, 0);
LineTo(hdc, 100*4+450, (int)-greatest+600);

//画出代表最小数的直线
MoveToEx(hdc, -100*4+450, (int)-least+600, 0);
LineTo(hdc, 100*4+450, (int)-least+600);


//依次画出x取-100、-99、……、-1时的点
for (int i=-100; i<0; i++) {
x=i;
y=0;
for (int j=0; j y+=pow(q[j], x);
}
y/=const_q;
y=pow(y, 1/x);
Ellipse(hdc, (int)x*4+450-2, (int)-y+600-2, (int)x*4+450+2, (int)-y+600+2);
}

//画出x取0时的点
y=1;
for (int i=0; i y*=pow(q[i], (double)1/const_q);
}
Ellipse(hdc, (int)450-4, (int)-y+600-4, (int)450+4, (int)-y+600+4);


//依次画出x取1、2、……、99时的点
for (int i=1; i<100; i++) {
x=i;
y=0;
for (int j=0; j y+=

首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇来自chrome的代码里的一个模板 下一篇Axis2/C基础入门

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: