首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

好心人帮助啊···这是对以前的题目的补充

2012-08-28 
热心人帮助啊这是对以前的题目的补充此为第一题:希望再看看可以进这里看看:这里是第一题,一起回复出来的就

热心人帮助啊···这是对以前的题目的补充
此为第一题:

希望再看看可以进这里看看:这里是第一题,一起回复出来的就一起给···
http://topic.csdn.net/u/20120728/17/52ac32df-37c9-4c62-a205-49bf55c32d65.html?seed=1439709866&r=79266952#r_79266952

[解决办法]
仅供参考

C/C++ code
#include <stdio.h>#include <stdlib.h>#include <conio.h>#include <graphics.h>int xs[10000];int ys[10000];int i=0,xx,yy;int fc,bc;void push(int x,int y) {    xs[i]=x;    ys[i]=y;    if (i<10000-1) {        i=i+1;    } else {        printf("stack overflow!\n");        exit(1);    }}void pop(void) {    i=i-1;    xx=xs[i];    yy=ys[i];}int check(int x,int y) {    int c;    c=getpixel(x,y); /* 获取当前点的颜色 */    return ((c!=bc)&&(c!=fc));/* 如果颜色为边界色或填充色则不填充 */}void seedfilling(int x,int y,int fill_color,int boundary_color) {    fc=fill_color;    bc=boundary_color;    push(x,y);    while (1) {        if (i<=0) return;        pop();        if (check(xx,yy)) {            putpixel(xx, yy, 14);getch();  /* 加上这行显示当前填充状态 */            putpixel(xx, yy, fill_color); /* 画点 */            if (check(xx-1,yy  )) push(xx-1,yy  );            if (check(xx  ,yy+1)) push(xx  ,yy+1);            if (check(xx  ,yy-1)) push(xx  ,yy-1);            if (check(xx+1,yy  )) push(xx+1,yy  );            /* 去掉下面四句就是四连通 */            if (check(xx-1,yy-1)) push(xx-1,yy-1);            if (check(xx-1,yy+1)) push(xx-1,yy+1);            if (check(xx+1,yy-1)) push(xx+1,yy-1);            if (check(xx+1,yy+1)) push(xx+1,yy+1);        }    }}void main() {    int a,b,color;    int gdriver = DETECT, gmode, errorcode;    int poly[10];    initgraph(&gdriver, &gmode, "d:\\bc\\bgi");    a=150;    b=140;    color=4;    poly[0]=110;/* 第一个点的x坐标以及y坐标 */    poly[1]=110;    poly[2]=200;/* 第二点 */    poly[3]=105;    poly[4]=170;/* 第三点 */    poly[5]=120;    poly[6]=150;/* 第四点 */    poly[7]=170;    poly[8]=110;/* 多边形的起点与终点一样 */    poly[9]=110;    drawpoly(5,poly);/* 显示各点连接起来的多边形 */    /* 保证边界对八连通是封闭的 */    setviewport(0,1,600,300,0);    drawpoly(5,poly);/* 显示各点连接起来的多边形 */    setviewport(1,0,600,300,0);    drawpoly(5,poly);/* 显示各点连接起来的多边形 */    setviewport(1,1,600,300,0);    drawpoly(5,poly);/* 显示各点连接起来的多边形 */    /* 恢复默认viewport */    setviewport(0,0,600,300,0);    seedfilling(a,b,color,15);  /* 种子填充多边形 */    getch();    closegraph();}
[解决办法]
看看我这个怎么样,简约而不简单。
C/C++ code
#include <stdio.h>#include <stdlib.h>#include <string.h>int foo(int k, int m){    int count = 0;    int *a = (int*)malloc(m*sizeof(int));       int pos = 0;    a[pos] = 0;    int n = k*k;    int *b = (int*)malloc(n*sizeof(int));    while (true)    {        while (!(a[pos]>n-1 || pos>=m-1))        {                    a[pos+++1] = a[pos] + 1;        }        if (a[pos]>n-1)        {            if (pos>0)            {                a[--pos]++;            }            else            {                break;            }                }        else        {                        memset(b, 0, n*sizeof(int));            while (pos>=0)            {                int row = a[pos]/k;                int column = a[pos]%k;                b[row*k+column] = 1;                int i;                for(i=-1; i<3; i+=2)                {                    if(row+i>-1 && row+i<k)                    {                        b[(row+i)*k+column] = 1;                    }                    if(column+i>-1 && column+i<k)                    {                        b[row*k+column+i] = 1;                    }                }                                --pos;            }            int i;            for(i=0; i<n&&b[i]==1; ++i);                    if(i==n)            {                ++count;            }            a[pos=m-1]++;        }    }    return count;}void main(){    int n;    int m;    scanf("%d %d", &n,&m);    printf("%d\n", foo(n,m));    } 


[解决办法]
这题类似N后问题呀。
楼主怎么老是求源代码。。。自己动手写点东西啊。

热点排行