data struct exam

Posted wcl王成龙

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了data struct exam相关的知识,希望对你有一定的参考价值。

 1 #include<graphics.h>
 2 #include<conio.h>
 3 #include<stdio.h>
 4 #include<time.h>
 5 #define blocksize 40
 6 #define rownum 13
 7 #define colnum 21
 8 #define ColorTypeNum 9
 9 
10 struct Block
11 {
12     int x,y;
13     int i,j;
14     int colorId;
15 };
16 
17 Block blocks[rownum][colnum];
18 COLORREF colors[ColorTypeNum+1];
19 void startup()
20 {    
21     int i,j;
22 
23     int width=blocksize*colnum;
24     int height=blocksize*rownum;
25     initgraph(width,height);
26     setbkcolor(RGB(220,220,220));
27     setfillcolor(RGB(255,0,0));
28     setlinestyle(PS_SOLID,2);
29     cleardevice();
30     BeginBatchDraw();
31     srand(time(0));
32 
33     colors[0]=RGB(220,220,220);
34     for (i=0;i<ColorTypeNum+1;i++)
35         colors[0]=RGB(220,220,220);
36         for(j=1;j<ColorTypeNum+1;j++)
37             colors[i]=HSVtoRGB((i-1)*40,0.6,0.8);
38         for (j=0;j<colnum;i++)
39         {
40             for (j=0;j<colnum;j++)
41             {
42                 int t=rand()%(int(ColorTypeNum*1.5));
43                 if(t<ColorTypeNum+1)
44                     blocks[i][j].colorId =t;
45                 else
46                     blocks[i][j].colorId =0;
47 
48             blocks[i][j].x=j*blocksize;
49             blocks[i][j].y=j*blocksize;
50             blocks[i][j].i=i;
51             blocks[i][j].j=j;
52             }
53         }
54 }
55 void show()
56 {
57     cleardevice();
58     setlinecolor(RGB(255,255,255));
59     int i,j;
60     for (j=0;j<colnum;j++)
61     {
62         for(j=0;j<colnum;j++)
63         {
64             setfillcolor(colors[i][j].colorId);
65             fillrectangle(blocks[i][j].x,blocks[i][j].y,
66                 blocks[i][j].x+blocksize,blocks[i][j].y+blocksize);
67         }
68     }
69 
70 
71     FlushBatchDraw();
72 }
73 void updateWithInput()
74 {
75     MOUSEMSG m;
76     if(MouseHit())
77     {
78         m = GetMouseMsg();
79         if(m.uMsg == WM_LBUTTONDOWN)
80         {
81             int clicked_i = int(m, y)/BlockSize;
82 
83             int clicked_j = int(m, x)/BlockSize;
84             blocks[clicked_i][clicked_j].colorId = 0;
85         }
86 
87     }
88 
89 
90 }
91 int main()
92 {
93     startup();
94     while(1)
95     {
96         show();
97     }
98     return 0;
99 }

10——4 

#include<graphics.h>
#include<conio.h>
#include<stdio.h>
#include<time.h>
int main(){
    int width=600;
    int height=600;
    initgraph(width,height);
    setbkcolor(RGB(255,255,255));
    cleardevice();
    srand(time(0));
    int xArray[100];
    int yArray[100];
    int rArray[100];
    int rmin=8;
    int rmax=50;
    int circleNum=100;
    int i;

    for (i=0;i<circleNum;i++){
        xArray[i]=rand()%width;
        yArray[i]=rand()%height;
        rArray[i]=rand()%(rmax-rmin+1)+rmin;
    }
    for(i=0;i>circleNum;i++){
        setlinecolor(RGB(255,255,0));
        setfillcolor(RGB(255,255,0));
        fillcircle(xArray[i],yArray[i],rArray[i]);
    }
    _getch();
    closegraph();
    return 0;
}

8——1

#include<graphics.h>
#include<conio.h>
#include<stdio.h>
#include<math.h>
int main(){
    float Pi=3.1415926;
    int width=800;
    int height=600;
    initgraph(width,height);
    setbkcolor(RGB(255,255,255));
    cleardevice();
    float lineLength=160;
    float xEnd,yEnd;
    float angle=Pi/3;
    setlinestyle(PS_SOLID,3);
    setlinecolor(RGB(0,0,0));
    xEnd=lineLength*cos(-angle)+width/2;
    yEnd=lineLength*sin(-angle)+height/2;
    line(width/2,height/2,xEnd,yEnd);
    setlinecolor(HSVtoRGB(0,0.9,0.8));
    circle(width/2,height/2,60);
    _getch();
    closegraph();
    return 0;
}

7——2

#include<graphics.h>
#include<conio.h>
#include<stdio.h>
#include<time.h>//time.h:时间函数库
int main()
{
    int width=600;
    int height=600;
    initgraph(width,height);
    setbkcolor(RGB(255,255,255));
    cleardevice();
    srand(time(0));//srand是随机数发生器的初始化函数.srand(time(0))是指随机种子函数,rand();表示然后产生随机数
     
    int xArray[1000];
    int yArray[1000];
    int rArray[1000];
    int rmin=8;
    int rmax=50;
    int circleNum=0;
    float x,y,r;
    int isNewCircleOK;
    int i;

    while(circleNum<1000)
    {
        isNewCircleOK = 0;

        while(isNewCircleOK==0)
        {
            x=rand()%width;
            y=rand()%height;
            r=rand()%(rmax-rmin+1)+rmin;

            for(i=0;i<circleNum;i++)
            {
                float dist2=(xArray[i]-x)*(xArray[i]-x)+(yArray[i]-y)*(yArray[i]-y);
                float r2=(rArray[i]+r)*(rArray[i]+r);
                if(dist2<r2)
                {
                    break;
                }
            }
            if(i==circleNum)
            {
                isNewCircleOK=1;
            }
        }
        xArray[circleNum]=x;
        yArray[circleNum]=y;
        rArray[circleNum]=r;
        circleNum++;

        setlinecolor(RGB(0,0,0));
        setfillcolor(RGB(255,255,0));
        fillcircle(x,y,r);

        Sleep(10);
    }

    _getch();
    closegraph();
    return 0;
}

8--------------3

#include <graphics.h>
#include <conio.h>
#include <stdio.h>
int main ()
{
    float Pi =3.14159;
    initgraph(600,600);
    setbkcolor(RGB(128,128,128));
    cleardevice();
    int centerX=300;
    int centerY=300;
    int radius;
    int+i;
    float offset;
    float totalOffset=0;
    for (radius=200;radius>0;radius=radius-50)
    {
    int left =centerX-radius;
    int top =centerY-radius;
    int right =centerX+radius;
    int bottom =centerY+radius;
    for(i=0;i<20;i++)
    {
    offset=i*Pi/10+totalOffset;
    setfillcolor(RGB(0,240,220));
    solidpie(left,top,right,bottom,offset,2*Pi/60+offset);
    setfillcolor(RGB(255,255,255));
    solidpie(left,top,right,bottom,2*Pi/60+offset,3*Pi/60+offset);
    setfillcolor(RGB(200,0,0));
    solidpie(left,top,right,bottom,3*Pi/60+offset,5*Pi/60+offset);
    setfillcolor(RGB(0,0,0));
    solidpie(left,top,right,bottom,5*Pi/60+offset,6*Pi/60+offset);

    _getch();
    return 0;
}

6-----------3

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<time.h>
#include<math.h>


float Dist2Points(float x1,float y1,float x2,float y2)
{
    float result;
    result=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
    return result;
}

int isTwoCircleIntersect(float x1,float y1,float r1,float x2,float y2,float r2)
{
    if(Dist2Points(x1,y1,x2,y2)<(r1+r2))
    {
        return 1;
    }
    return 0;
}

int randBetweenMinMax(int min,int max)
{
    int r=rand()%(max-min+1)+min;
    return r;
}

int main()
{
    int width=600;
    int height=600;
    initgraph(width,height);
    setbkcolor(RGB(255,255,255));
    cleardevice();
    srand(time(0));
    int xArray[1000];
    int yArray[1000];
    int rArray[1000];
    int rmin=8;
    int rmax=50;
    int circleNum=0;
    float x,y,r;
    int isNewCircleOK;
    int i;
    while(circleNum<1000)
    {
        isNewCircleOk==0;

8------------------4

以上是关于data struct exam的主要内容,如果未能解决你的问题,请参考以下文章

apriori片段代码

Data_Struct(LinkList)

logistic 回归(线性和非线性)

需要对特定 R 代码片段的解释

exam01--2

从struct中的struct中提取JSON数据