求C语言程序设计实例,要100行以上,求高手解答,不要太难

不要带汉字的,大一水平啊,别弄得太难啊,看不懂啊~~呜呜呜呜.
刚才那个人能在发一下吗?我没有接到啊~~~~.
太少了啊,刚才那个

/* Note:Your choice is C IDE */
#include "stdio.h"
#include "string.h"
#define MAX 370000
typedef struct
{
char string[12];
int state;
int x;
int y;
}string;
typedef struct Queue
{
string queue[MAX];
int low;
int top;
}queue;
queue s1,s2;
char start[12];
char goal[9]={"123456789"};
char flag[MAX];
char step[2][MAX];
int xd[4]={0,-1,0,1};
int yd[4]={1,0,-1,0};
int fact[9]={1,1,2,6,24,120,720,5040,40320};
int cantor(char *s){
int i,j,count;
int sum=0;
for(i=0;i<8;i++)
{
count=0;
for(j=i+1;j<=8;j++)
if(s[i]>s[j])
count++;
sum+=fact[8-i]*count;
}
return sum;
}
int judge(int x,int y)
{
if(x>=0&&x<3&&y>=0&&y<3)
return 1;
return 0;
}
int ckey(char *s){
int i,j;
int sum=0,count;
for(i=8;i>=0;i--)
{
count=0;
if(s[i]=='9')
continue;
for(j=i-1;j>=0;j--)
{
if(s[j]=='9')
continue;
if(s[i]<s[j])
count++;
}
sum+=count;
}
if(sum%2)
return 0;
return 1;
}
int BFS()
{
string t1,t2;
int i;
while(s1.low<s1.top&&s2.low<s2.top)
{
t1=s1.queue[++s1.low];
for(i=0;i<4;i++)
{
if(judge(t1.x+xd[i],t1.y+yd[i]))
{
int currentstate,z,nz;
char t[12];
strcpy(t,t1.string);
z=3*t1.x+t1.y;
nz=3*(t1.x+xd[i])+t1.y+yd[i];
t[z]^=t[nz];
t[nz]^=t[z];
t[z]^=t[nz];
currentstate=cantor(t);
if(!flag[currentstate])
{
flag[currentstate]=1;
step[0][currentstate]=step[0][t1.state]+1;
strcpy(s1.queue[++s1.top].string,t);
s1.queue[s1.top].x=t1.x+xd[i];
s1.queue[s1.top].y=t1.y+yd[i];
s1.queue[s1.top].state=currentstate;
}
else if(flag[currentstate]==2)
return step[0][t1.state]+step[1][currentstate]+1;
}
}
t2=s2.queue[++s2.low];
for(i=0;i<4;i++)
{
if(judge(t2.x+xd[i],t2.y+yd[i]))
{

int currentstate,z,nz;
char t[12];
strcpy(t,t2.string);
z=3*t2.x+t2.y;
nz=3*(t2.x+xd[i])+t2.y+yd[i];
t[z]^=t[nz];
t[nz]^=t[z];
t[z]^=t[nz];
currentstate=cantor(t);
if(!flag[currentstate])
{
flag[currentstate]=2;
strcpy(s2.queue[++s2.top].string,t);
step[1][currentstate]=step[1][t2.state]+1;
s2.queue[s2.top].x=t2.x+xd[i];
s2.queue[s2.top].y=t2.y+yd[i];
s2.queue[s2.top].state=currentstate;
}
if(flag[currentstate]==1)
return step[1][t2.state]+step[0][currentstate]+1;
}
}

}
return -1;
}
void main()
{
int i,result;
char hb[9];
while(scanf("%s",hb)!=EOF)
{
result=0;
start[0]=hb[0];
for(i=1;i<9;i++)
{
scanf("%s",hb);
start[i]=hb[0];
}
for(i=0;i<9;i++)
if(start[i]=='x')
{
start[i]='9';
break;
}
if(!ckey(start))
result=-1;
else if(!strcmp(start,goal))
result=0;
else
{
memset(flag,0,sizeof(flag));
memset(step,0,sizeof(step));
s1.low=s1.top=-1;
s2.low=s2.top=-1;
flag[s1.queue[++s1.top].state=cantor(start)]=1;
flag[s2.queue[++s2.top].state=cantor(goal)]=2;
strcpy(s1.queue[s1.top].string,start);
strcpy(s2.queue[s2.top].string,goal);
s1.queue[s1.top].x=i/3;
s1.queue[s1.top].y=i%3;
s2.queue[s2.top].x=2;
s2.queue[s2.top].y=2;
result=BFS();
}
if(result<0)
printf("unsolvable\n");
else printf("%d\n",result);
}
}
这是经典的八数码问题的求解。。。双向BFS,。。。问题是给出一个初始状态。。求到达目标状态最小需要多少步。。。。其中目标状态固定。。。为1 2 3 4 5 6 7 8 x。。。x代表空格。。这九个数代表3*3的矩阵。。说白了就是小时候玩的拼图游戏。。。我把注释都消了。。。你慢慢看。。。。追问

有没有简单一点的哈?大一水平啊,顺便解释一下大概是什么意思啊

追答

我也是大一水平。。。。。。。
简单点的有。。。但是没这么长。。。
这题目是英文的。。你看的懂不??
要是看的懂我就把题目发上来

追问

那简单一点的有没有快到100的啊?或者100多的,150的都行

追答

好吧
你把QQ邮箱给我。。。
我把题目和程序一起给你。。。
这的字数超过了限制

追问

[email protected]

追答

发给你了。。给我分吧

温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-06-27
#include "stdio.h"
#include "graphics.h"
#include "math.h"

void Draw(int color);

int t_x=320,t_y=240,t_r=40; /* SUN太阳参数,圆心坐标及半径 */
int d_x,d_y,d_r=20; /* D地球参数 */
int y_x,y_y,y_r=5; /* Y月亮参数 */

int j_x,j_y,j_r=8; /* J星参数 */
int m_x,m_y,m_r=10; /* M星参数 */
int s_x,s_y,s_r=4; /* S星参数 */

float th1=0,th2=0,th3=0,th4=0,th5=0;/* 各星相对太阳的角度 */

main()
{
int gd=DETECT,gm;

int key=0; /* 保存键盘值?*/
int i;
float r;
initgraph(&gd,&gm,"");

Draw(12); /* 先画一个 */
while(key!=0x11b) /* 如果按键==ESC键则退出 */
{
Draw(0); /* 用背景色把画好的图洗掉 */
if(bioskey(1)) /* 如果有按键?*/
{
key=bioskey(0); /* 取得按键的值 */
if(key==0x4b00) t_x-=10; /* 向上方向键 */
if(key==0x4d00) t_x+=10; /* 向下方向键 */
if(key==0x4800) t_y-=10; /* 向左方向键 */
if(key==0x5000) t_y+=10; /* 向右方向键 */
}
th1+=0.001256; /* 各星按角度移动 */
if(th1>=6.28) th1-=6.28; /* 如果转了一圈,按0角度从新计算 */
th2+=0.01256;
if(th2>=6.28) th2-=6.28;
th3+=0.002512;
if(th3>=6.28) th3-=6.28;
th4+=0.000314;
if(th4>=6.28) th4-=6.28;
th5+=0.00628;
if(th5>=6.28) th5-=6.28;
r+=0.5; /* 让太阳半径动态增加 */
if(r>=40) r=20; /* 增大40后用从20从新开始 */
t_r=(int)r;
Draw(12); /* 用颜色12画出图形 */
delay(1000); /* 稍等1秒钟看一下结果 */
}
closegraph();
}

void Draw(int color) /* 画图形 */
{
setcolor(color);
circle(t_x,t_y,t_r); /* 画太阳?*/
outtextxy(t_x-10,t_y-4,"SUN"); /* 显示太阳符号SUN */

d_x=t_x+130*cos(th1); /* 根据太阳位置计算地球位置X */
d_y=t_y+130*sin(th1); /* 根据太阳位置计算地球位置Y */
circle(d_x,d_y,d_r); /* 画地球 */
outtextxy(d_x-4,d_y-4,"D"); /* 显示地球符号D */

y_x=d_x+40*cos(th2); /* 根据地球位置计算月亮位置X */
y_y=d_y+40*sin(th2); /* 根据地球位置计算月亮位置Y */
circle(y_x,y_y,y_r); /* 画月亮 */
outtextxy(y_x-3,y_y-4,"Y"); /* 显示月亮符号Y */

j_x=t_x+60*cos(th3); /* 根据太阳位置计算J星位置X */
j_y=t_y+60*sin(th3); /* 根据太阳位置计算J星位置Y */
circle(j_x,j_y,j_r); /* 画J星 */
outtextxy(j_x-4,j_y-4,"J"); /* 显示J星符号J */

m_x=t_x+200*cos(th4); /* 根据太阳位置计算M星位置X */
m_y=t_y+200*sin(th4); /* 根据太阳位置计算M星位置Y */
circle(m_x,m_y,m_r); /* 画M星 */
outtextxy(m_x-4,m_y-4,"M"); /* 显示M星符号M */

s_x=t_x+230*cos(th5); /* 根据太阳位置计算S星位置X */
s_y=t_y+230*sin(th5); /* 根据太阳位置计算S星位置Y */
circle(s_x,s_y,s_r); /* 画S星,S星太小,所以没有显示符号 */
}
这个希望能用的上,我们也做这个,也是一样的要求
第2个回答  2011-06-26
KindergartenTime Limit: 2000MS Memory Limit: 65536K
Total Submissions: 2597 Accepted: 1161

Description

In a kindergarten, there are a lot of kids. All girls of the kids know each other and all boys also know each other. In addition to that, some girls and boys know each other. Now the teachers want to pick some kids to play a game, which need that all players know each other. You are to help to find maximum number of kids the teacher can pick.

Input

The input consists of multiple test cases. Each test case starts with a line containing three integers
G, B (1 ≤ G, B ≤ 200) and M (0 ≤ M ≤ G × B), which is the number of girls, the number of boys and
the number of pairs of girl and boy who know each other, respectively.
Each of the following M lines contains two integers X and Y (1 ≤ X≤ G,1 ≤ Y ≤ B), which indicates that girl X and boy Y know each other.
The girls are numbered from 1 to G and the boys are numbered from 1 to B.

The last test case is followed by a line containing three zeros.

Output

For each test case, print a line containing the test case number( beginning with 1) followed by a integer which is the maximum number of kids the teacher can pick.

Sample Input

2 3 3
1 1
1 2
2 3
2 3 5
1 1
1 2
2 1
2 2
2 3
0 0 0
Sample Output

Case 1: 3
Case 2: 4
Source

2008 Asia Hefei Regional Contest Online by USTC

注:二分图的最大团等于该图的补图的最大独立集。
第3个回答  2011-06-29
#include <stdio.h>
#define N 11

int main()
{
char a[N][N];
int m=5,n=0,x,y;
char *p,*q;
p=q=&a[0][0];

for(y=0;y<N;y++)
{
for(x=0;x<N;x++)
{
a[y][x]=' ';
}
}

for(n=0;n<=m;n++)
{
p=q=&a[n][m];
p=p+n;
q=q-n;
*p='*';
*q='*';

}
// printf("%d\n",n);

for(n=10;n>5;n--)
{
p=q=&a[n][m];
p=p-(10-n);
q=q+(10-n);
*p='*';
*q='*';

}

for(n=2;n<=m;n++)
{
p=q=&a[n][m];
p=p+(n-2);
q=q-(n-2);
*p='*';
*q='*';

}

for(n=8;n>5;n--)
{
p=q=&a[n][m];
p=p-(10-n-2);
q=q+(10-n-2);
*p='*';
*q='*';

}

for(n=4;n<=m;n++)
{
p=q=&a[n][m];
p=p+(n-4);
q=q-(n-4);
*p='*';
*q='*';

}

for(n=6;n>5;n--)
{
p=q=&a[n][m];
p=p-(10-n-4);
q=q+(10-n-4);
*p='*';
*q='*';

}

for(y=0;y<N;y++)
{
for(x=0;x<N;x++)
{
printf("%c ",*(*(a+y)+x));
}
printf("\n");
}

return 0;
}
第4个回答  2011-06-28
LS几个太犀利了
大一就学数据结构
牛B