void Init_Data()
{
int i
for( i=0i<POINTi++)
{
Snow[i].x=0
Snow[i].y=0
Snow[i].size=0
}
for( i=0i<MaxXi++)
Map[i]=MaxY
}
显示:
void MakeSnow()
{
int i
if( CurSnow>=POINT ) return
for( i=0Snow[i].sizei++ )
CurSnow++
Snow[i].x=random(MaxX)
Snow[i].y=random(DOWNSPEED)
Snow[i].size=random(MaxSize)+1
}
设定显示坐标
void ShowSnow( int x, int y, int size, int flag )
{
int color=0
if ( flag ) color=15
switch( size )
{
case 1:
putpixel( x, y, color )
break
case 2:
setcolor( color )
line( x-1, y-1, x+1, y+1 )
line( x-1, y+1, x+1, y-1 )
break
case 3:
setcolor( color )
line( x-1, y-1, x+1, y+1 )
line( x-1, y+1, x+1, y-1 )
/*
line( x-2, y-2, x+2, y+2 )
line( x-2, y+2, x+2, y-2 )*/
line( x-2, y, x+2, y )
line( x, y-2, x, y+2 )
break
}
}
雪花移动效果:
void Move( int n, int tox, int toy )
{
int x, y, size, i, j
float person
x=Snow[n].x
y=Snow[n].y
size=Snow[n].size
/* check end */
j=y
if( x<tox )
{
person=(DOWNSPEED *1.0) / ( tox-x )*1.0
for( i=xi<=toxi++ )
{
if( j>=Map[i] )
{
tox=i-size
break
}
j+=(int)( (i-x+1)*person )
}
}
else if( x>tox )
{
person=(DOWNSPEED *1.0) / ( x-tox )*1.0
for( i=xi>=toxi-- )
{
if( j>=Map[i] )
{
tox=i+size
break
}
j+=(int)( (x-i+1)*person )
}
}
if( y+DOWNSPEED>=Map[tox] )
{
switch( size )
{
case 1:
Map[x]--
break
case 2:
Map[x]-=2
if( x>0 &&Map[x-1]>Map[x] ) Map[x-1]=Map[x]
if( x<MaxX-1 &&Map[x+1]>Map[x] ) Map[x+1]=Map[x]
break
case 3:
Map[x]-=3
if( x>1 &&Map[x-2]>Map[x] ) Map[x-1]=Map[x]
if( x>0 &&Map[x-1]>Map[x] ) Map[x-1]=Map[x]
if( x<MaxX-2 &&Map[x+2]>Map[x] ) Map[x+1]=Map[x]
if( x<MaxX-1 &&Map[x+1]>Map[x] ) Map[x+1]=Map[x]
break
}
CurSnow--
y=Map[x]+size
Snow[n].x=x
Snow[n].y=y
Snow[n].size=0
}
else /* not end */
{
Snow[n].x=tox
Snow[n].y=toy
}
}
这个程序寻找的是10000以内的雷劈数,测试有效。本人能力有限,算法显得拙劣,运算速度慢,可能的话你自己优化下算法吧。#include<stdio.h>#include<iomanip.h>
#include<math.h>#define N 10000void Ana(int a,int b,int c)
{
int x,y,i,j[2]={0}
double m,n
m=c*c
x=a
y=bfor(i=0j[0]==0||j[1]==0i++)
{
if(x!=0)
x=x/10
if(x==j[0])
j[0]=i+1
if(y!=0)
y=y/10
if(y==j[1])
j[1]=i+1
}
n=a*pow(10,j[1])+b
if(n==m)
printf("%d %d---->%.0lf\n",a,b,m)
n=b*pow(10,j[0])+a
if(n==m)
printf("%d %d---->%.0lf\n",b,a,m)
}void main()
{
int i,j,sum=0
for(i=1i<Ni++)
for(j=i+1j<=Nj++)
{
sum=i+j
Ana(i,j,sum)
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)