當前位置:首頁 » 操作系統 » 十個球源碼

十個球源碼

發布時間: 2023-06-01 00:46:05

⑴ 用10個球在下面的數位表中你能擺出多少個不同的數試一試寫一寫。

用十個球可以擺出下面的數:
十位 個位
1個 9個,寫作:19
2個 8個,寫作:28
3個 7個,寫作碧攔檔:37
4個 6個,寫作:46
5個衡辯 5個,寫作:55
6個 4個,寫作:64
7個 3個,寫作:73
8個 2個,寫作:82
9個 1個,寫悔亂作:91
答:能擺出9個不同的數。

⑵ 有10個1球隨機抽取兩個組合,(ab和ba視為一樣)問最多能組成多少個,C#實現各位大俠指教一下,代碼詳細點

你這是個排列組合問題啊升悉
就是求C10 2
public Form1()
{
InitializeComponent();
Zuhe();
}
public void Zuhe()
{int a=10,b=2,c=1,d=1,i,f; //這就是C的那個 10 和2,你可以任意修改10和2的值
for(i=0;i<10;i++) //頃前求10!
{
c=c*a;
a--;
}
for(i=0;i<10;i++) //求2!
{
d=d*b;
b--;
}
f=c/d; /雀笑清/求C10 2的值
console.write("答案為{0}",+f);
}

⑶ 10個球取5個球演算法

編號1,2,3.,10得十個球中
5個奇數,5個櫻辯偶數
5個數全為奇數,這樣的取法有1種
5個數3個奇數脊顫缺,2個偶數,這樣的取法有C(5,3)*C(5,2)=100
5個數1個奇數,4個偶數,這樣的取洞蘆法有C(5,1)*C(5,4)=25
共有126種

c語言 雙色球 求源碼

#包括中
#包括中

#包括

國際主要()

{整型紅[6]; / *藍色1-33 * /

整數; / * 1-16 * /

INT I,J;

詮釋tmp目錄;

函數srand((無符號)時間(NULL));

我= 0;

而(I <6)

{

TMP =(1.0 * RAND()/ RAND_MAX)* 33 + 1;

為(J = 0;<I; J + +)

{

如果(紅[J] == TMP)

{

突破;

如果(十== I)

{

紅[I] = tmp目錄;

i + +;

}

}

藍色=(1.0 * RAND()/ RAND_MAX)* 16 + 1;

就(i = 0; I <6; i + +)

{

的printf(「%d個,」紅[一]);

的printf(「\ n%d個」,藍);

返回0;
}

⑸ 求 一個FLASH AS3.0做的 多個小球在一個框里互相碰撞的源碼

var speed:uint=5//自定義速度
var bounce:Number=-1//自定義摩擦系數(碰到了不停下)
for(var i:uint=0;i<8;i++){
var ball:Ball=new Ball();
addChild(ball)
ball.x=Math.random()*(stage.stageWidth-ball.width)
ball.y=Math.random()*(stage.stageHeight-ball.height)
ball.addEventListener(Event.ENTER_FRAME,go);
ball.ids=Math.random()*2*Math.PI//自定義一個360度桐穗隨機角度
ball.vx=Math.cos(ball.ids)*speed//自定義有方向的速度
ball.vy=Math.sin(ball.ids)*speed
}
function go(e:Event):void{
var ball:MovieClip=MovieClip(e.target)
ball.x+=ball.vx//讓目標動起來
ball.y+=ball.vy
if(ball.x<0){//判斷出了舞台
ball.x=0
ball.vx*=bounce//出孫攔了舞台的左右,X速度的方向變成反向
}
if(ball.x>stage.stageWidth-ball.width){
ball.x=stage.stageWidth-ball.width
ball.vx*=bounce
}

if(ball.y<0){//除局凱卜了舞台的上下,Y速度的方向變成反響
ball.y=0
ball.vy*=bounce
}
if(ball.y>stage.stageHeight-ball.height){
ball.y=stage.stageHeight-ball.height
ball.vy*=bounce//同上
}
} 小球在舞台上相互碰撞

⑹ 求用C語言模擬簡單檯球運動的源代碼,不需要圖形化界面

這源代碼應該有個桌面類(Table),球類(Sphere),游戲類等等。我用C++
#pragma once (Table.h)
#endif // _MSC_VER > 1000
#include "Base.h"
#define MESH_D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX1)
class CTable:public CBase
{
public:
DWORD Render();
CTable(LPDIRECT3DDEVICE8 pD3DDevice,LPSTR pFilename);
virtual ~CTable();
LPD3DXMESH GetMeshTablePointer();
private:
void TransformTable();
LPDIRECT3DDEVICE8 m_pD3DDevice;
DWORD m_dwNumMaterials;
LPD3DXMESH m_pMeshTable;
D3DMATERIAL8 *m_pMeshTableMaterials;
LPDIRECT3DTEXTURE8 *m_pMeshTableTextures;
};#endif

#include "Table.h" (Table.cpp)
CTable::CTable(LPDIRECT3DDEVICE8 pD3DDevice,LPSTR pFilename)
{
LPD3DXBUFFER pMaterialsBuffer=NULL;
LPD3DXMESH pMeshTable=NULL;

m_pD3DDevice=pD3DDevice;

if(FAILED(D3DXLoadMeshFromX(pFilename,D3DXMESH_MANAGED,m_pD3DDevice,NULL,
&pMaterialsBuffer,&m_dwNumMaterials,&pMeshTable)))
{
m_pMeshTable=NULL;
m_pMeshTableMaterials=NULL;
m_pMeshTableTextures=NULL;

LogError("<li>Table Mesh '%s' failed to load",pFilename);
return;
}
D3DXMATERIAL *matMaterials=(D3DXMATERIAL*)pMaterialsBuffer->GetBufferPointer();
//Create two arrays. One to hold the materials and one to hold the textures
m_pMeshTableMaterials=new D3DMATERIAL8[m_dwNumMaterials];
m_pMeshTableTextures=new LPDIRECT3DTEXTURE8[m_dwNumMaterials];
for(DWORD i=0;i<m_dwNumMaterials;i++)
{
//Copy the material
m_pMeshTableMaterials[i]=matMaterials[i].MatD3D;

//Set the ambient color for the material(D3DX does not do this)
m_pMeshTableMaterials[i].Ambient=m_pMeshTableMaterials[i].Diffuse;
D3DCOLORVALUE rgbaSpecular={0.0f,0.0f,0.0f,0.0f};
m_pMeshTableMaterials[i].Specular=rgbaSpecular;
m_pMeshTableMaterials[i].Power=50.0f;
//Create the texture
char buffer[255];
sprintf(buffer,"textures/%s",matMaterials[i].pTextureFilename);
if(FAILED(D3DXCreateTextureFromFile(m_pD3DDevice,
buffer, &m_pMeshTableTextures[i])))
{
m_pMeshTableTextures[i]=NULL;
}
}
//finished with the material buffer,so release it
SafeRelease(pMaterialsBuffer);
//Make sure that the normals are setup for mesh
pMeshTable->CloneMeshFVF(D3DXMESH_MANAGED,MESH_D3DFVF_CUSTOMVERTEX,m_pD3DDevice,&m_pMeshTable);
SafeRelease(pMeshTable);
// D3DXComputeNormals(m_pMesh);
LogInfo("<li>Mesh '%s' loaded OK",pFilename);
}
CTable::~CTable()
{
SafeDelete(m_pMeshTableMaterials);

if(m_pMeshTableTextures != NULL)
{
for(DWORD i=0;i<m_dwNumMaterials;i++)
{
if(m_pMeshTableTextures[i])
SafeRelease(m_pMeshTableTextures[i]);
}
}
SafeDelete(m_pMeshTableTextures);
SafeRelease(m_pMeshTable);
LogInfo("<li>Table Mesh destroyed OK");
}
DWORD CTable::Render()
{
TransformTable();
if(m_pMeshTable!=NULL)
{
for(DWORD i=0;i<m_dwNumMaterials;i++)
{
m_pD3DDevice->SetMaterial(&m_pMeshTableMaterials[i]);
m_pD3DDevice->SetTexture(0,m_pMeshTableTextures[i]);

m_pMeshTable->DrawSubset(i);
}

return m_pMeshTable->GetNumFaces();
}
else
return 0;
}
LPD3DXMESH CTable::GetMeshTablePointer()
{
return m_pMeshTable;
}
void CTable::TransformTable()
{
D3DXMATRIX matWorld;
D3DXMatrixTranslation(&matWorld,0,0,0);
m_pD3DDevice->SetTransform(D3DTS_WORLD,&matWorld);
}
(Sphere.h)
#if !defined (AFX_SPHERE_H__FC705F3B_568E_4973_B608_B8F7700D9ECE__INCLUDED_)
#define AFX_SPHERE_H__FC705F3B_568E_4973_B608_B8F7700D9ECE__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "Base.h"

#define SPHERE_D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX1)

class CSphere:public CBase
{
private:
struct SPHERE_CUSTOMVERTEX
{
float x,y,z; //Position of vertex in 3D space
float nx,ny,nz; //Lighting Normal
float tu,tv; //Texture coordinates
};

struct SPHERE_STATE
{
D3DXVECTOR3 sVector; //Position of Centigram in 3D space
D3DXVECTOR3 vVector; //Direction of Velocity in 3D space
float v; //Speed of Sphere
};
SPHERE_STATE *m_pSphereState;

D3DXVECTOR3 m_vecSavePosition; //Save sphere position for collision bar
D3DXVECTOR3 m_vecSavePosition2; //Save sphere position for collision sphere
public:
BOOL SetMaterial(D3DCOLORVALUE rgbaDiffuse,D3DCOLORVALUE rgbaAmbient,
D3DCOLORVALUE rgbaSpecular,D3DCOLORVALUE rgbaEmissive,float rPower);
BOOL SetTexture(const char* szTextureFilePath);
DWORD Render();
CSphere(LPDIRECT3DDEVICE8 pD3DDevice,int iRings=20,int iSegments=20);
void MoveSphere();
void MoveSphereForUser(float x,float z);
virtual ~CSphere();
inline void SetSpherePosition(float x,float y,float z)
{
m_pSphereState->sVector.x=x;
m_pSphereState->sVector.y=y;
m_pSphereState->sVector.z=z;
};
inline void GetSpherePosition(D3DXVECTOR3 &vecSpherePos)
{
vecSpherePos=m_pSphereState->sVector;
};
inline void GetSavedSpherePosition(D3DXVECTOR3 &vecSavedSpherePos)
{
vecSavedSpherePos=m_vecSavePosition;
};
inline void GetSavedSpherePosition2(D3DXVECTOR3 &vecSavedSpherePos)
{
vecSavedSpherePos=m_vecSavePosition2;
};
inline void SaveSpherePosition()
{
m_vecSavePosition=m_pSphereState->sVector;
};
inline void SaveSpherePosition2()
{
m_vecSavePosition2=m_pSphereState->sVector;
};
inline void ContradictoryZv()
{
m_pSphereState->vVector.z=-m_pSphereState->vVector.z;
};
inline void ContradictoryXv()
{
m_pSphereState->vVector.x=-m_pSphereState->vVector.x;
};
void MirrorVAoubtAxis(D3DXVECTOR3 &n);
inline void ReceSphereVelocity(float percent)
{
m_pSphereState->v=m_pSphereState->v*percent;
};
inline float CheckSphereEnergy()
{
return m_pSphereState->v;
};
inline void SetSphereVelocityDir(const D3DXVECTOR3 &vDir)
{
m_pSphereState->vVector=vDir;
};
inline void SetSphereVelocity(const float &velocity)
{
m_pSphereState->v=velocity;
};
inline void GetSphereVelocityDir(D3DXVECTOR3 &vDir)
{
vDir=m_pSphereState->vVector;
};
inline float GetSphereVelocity()
{
return m_pSphereState->v;
};
inline void SetSphereStateToFalse()
{
m_bSphereInUse=FALSE;
};
inline void SetSphereStateToTrue()
{
m_bSphereInUse=TRUE;
};
inline BOOL GetSphereState()
{
return m_bSphereInUse;
};
void SetSphereVelocityAt_Y_NegativeAxis();
inline float GetSpherePosAt_Y_Axis()
{
return m_pSphereState->sVector.y;
};
private:
BOOL CreateIndexBuffer();
BOOL UpdateVertices();
BOOL CreateVertexBuffer();
void TransformSphere();
void TransformSphereForUser();
void UpdateSpherePosition();
void FrictionReseVelocity();
LPDIRECT3DDEVICE8 m_pD3DDevice;
LPDIRECT3DVERTEXBUFFER8 m_pVertexBuffer;
LPDIRECT3DTEXTURE8 m_pTexture;
D3DMATERIAL8 m_matMaterial;
LPDIRECT3DINDEXBUFFER8 m_pIndexBuffer;
int m_iRings;
int m_iSegments;
float m_fTotalDis;
D3DXVECTOR3 m_vecSphereRotationAxis;
BOOL m_bSphereInUse;
DWORD m_dwNumOfVertices;
DWORD m_dwNumOfIndices;
DWORD m_dwNumOfPolygons;
};#endif

⑺ 求C語言編寫的壁球小游戲的源代碼,謝謝。

速度和 接板 長度不能改

所以比較難玩

#include "graphics.h"
#include "stdio.h"
#include "conio.h" /*所需的頭文件*/

int on; /*聲明具有開關作用的全局變數*/
static int score; /*聲明靜態的記分器變數*/

/* 定義開始界面函數*/

int open()
{
setviewport(100,100,500,380,1); /*設置圖形窗口區域*/
setcolor(4); /*設置作圖色*/
rectangle(0,0,399,279); /*以矩形填充所設的圖形窗口區域*/
setfillstyle(SOLID_FILL,7); /*設置填充方式*/
floodfill(50,50,4); /*設置填充范圍*/
setcolor(8);
settextstyle(0,0,9); /*文本字體設置*/
outtextxy(90,80,"BALL"); /*輸出文本內容*/
settextstyle(0,0,1);
outtextxy(110,180,"version 1.0");
outtextxy(110,190,"made by ddt");
setcolor(128);
settextstyle(0,0,1);
outtextxy(120,240,"Press any key to continue......");
}

/*定義退出界面函數*/
int quitwindow()
{
char s[100]; /*聲明用於存放字元串的數組*/
setviewport(100,150,540,420,1);
setcolor(YELLOW);
rectangle(0,0,439,279);
setfillstyle(SOLID_FILL,7);
floodfill(50,50,14);
setcolor(12);
settextstyle(0,0,8);
outtextxy(120,80,"End");
settextstyle(0,0,2);
outtextxy(120,200,"quit? Y/N");
sprintf(s,"Your score is:%d",score);/*格式化輸出記分器的值*/
outtextxy(120,180,s);
on=1; /*初始化開關變數*/
}

/*主函數*/
main()
{
int gdriver,gmode;
gdriver=DETECT; /*設置圖形適配器*/
gmode=0; /*設置圖形模式*/
registerbgidriver(EGAVGA_driver);/* 注冊BGI驅動後可以不需要.BGI文件的支持運行 */
initgraph(&gdriver,&gmode,"");
setbkcolor(14);
open(); /*調用開始界面函數*/
getch(); /*暫停*/

while(1) /*此大循環體控制游戲的反復重新進行*/
{
int driver,mode,l=320,t=400,r,a,b,dl=5,n,x=200,y=400,r1=10,dx=-2,dy=-2;/*初始化小球相關參數*/
int left[100],top[100],right[100],bottom[100],i,j,k,off=1,m,num[100][100];/*方磚陣列相關參數*/
static int pp;
static int phrase; /*一系列起開關作用的變數*/
int oop=15;
pp=1;
score=0;
driver=DETECT;
mode=VGA;
registerbgidriver(EGAVGA_driver);
initgraph(&driver,&mode,"");
setbkcolor(10);
cleardevice(); /*圖形狀態下清屏*/
clearviewport(); /*清除現行圖形窗口內容*/
b=t+6;
r=l+60;
setcolor(1);
rectangle(0,0,639,479);
setcolor(4);
rectangle(l,t,r,b);
setfillstyle(SOLID_FILL,1);
floodfill(l+2,t+2,4);

for(i=0,k=0;i<=6;i++) /*此循環繪制方磚陣列*/
{
top[i]=k;
bottom[i]=top[i]+20;
k=k+21;
oop--;
for(j=0,m=0;j<=7;j++)
{
left[j]=m;
right[j]=left[j]+80;
m=m+81;
setcolor(4);
rectangle(left[j],top[i],right[j],bottom[i]);
setfillstyle(SOLID_FILL,j+oop);
floodfill(left[j]+1,top[i]+1,4);
num[i][j]=pp++;
}
}

while(1) /*此循環控制整個動畫*/
{
while(!kbhit())
{
x=x+dx; /*小球運動的圓心變數控制*/
y=y+dy;
if(x+r1>r||x+r1<r)
{ phrase=0;}
if((x-r1<=r||x+r1<=r)&&x+r1>=l)
{
if(y<t)
phrase=1;
if(y+r1>=t&&phrase==1)
{dy=-dy;y=t-1-r1;}
}

if(off==0)
continue;

for(i=0;i<=6;i++) /*此循環用於判斷、控制方磚陣列的撞擊、擦除*/

for(j=0;j<=7;j++)
{
if((x+r1<=right[j]&&x+r1>=left[j])||(x-r1<=right[j]&&x-r1>=left[j]))
{
if(( y-r1>top[i]&&y-r1<=bottom[i])||(y+r1>=top[i]&&y+r1<=bottom[i] ))
{
if(num[i][j]==0)
{continue; }
setcolor(10);
rectangle(left[j],top[i],right[j],bottom[i]);
setfillstyle(SOLID_FILL,10);
floodfill(left[j]+1,top[i]+1,10);
dy=-dy;
num[i][j]=0;
score=score+10;
printf("%d\b\b\b",score);
}
}
if((y+r1>=top[i]&&y+r1<=bottom[i])||(y-r1>=top[i]&&y-r1<=bottom[i]))
{
if((x+r1>=left[j]&&x+r1<right[j])||(x-r1<=right[j]&&x-r1>left[j]))
{
if(num[i][j]==0)
{ continue;}
setcolor(10);
rectangle(left[j],top[i],right[j],bottom[i]);
setfillstyle(SOLID_FILL,10);
floodfill(left[j]+1,top[i]+1,10);
dx=-dx;
num[i][j]=0;
score=score+10;
printf("%d\b\b\b",score);
}
}
}

if(x+r1>639) /*控制小球的彈射范圍*/
{dx=-dx;x=638-r1;}
if(x<=r1)
{dx=-dx;x=r1+1;}
if(y+r1>=479)
{off=0;quitwindow();break;}
if(y<=r1)
{dy=-dy;y=r1+1;}
if(score==560)
{off=0;quitwindow();break;}
setcolor(6);
circle(x,y,r1);
setfillstyle(SOLID_FILL,14);
floodfill(x,y,6);
delay(1000);
setcolor(10);
circle(x,y,r1);
setfillstyle(SOLID_FILL,10);
floodfill(x,y,10);
}

a=getch();
setcolor(10);
rectangle(l,t,r,b);
setfillstyle(SOLID_FILL,10);
floodfill(l+2,t+2,10);
if(a==77&&l<=565) /*鍵盤控制設定*/
{dl=20;l=l+dl;}
if(a==75&&l>=15)
{dl=-20;l=l+dl;}
if(a=='y'&&on==1)
break;
if(a=='n'&&on==1)
break;
if(a==27)
{quitwindow();off=0;}
r=l+60;
setcolor(4);
rectangle(l,t,r,b);
setfillstyle(SOLID_FILL,1);
floodfill(l+5,t+5,4);
delay(100);
}
if(a=='y'&&on==1) /*是否退出遊戲*/
{break;}
if(a=='n'&&on==1)
{ continue;}
}
closegraph();

}

你不是要求在TC里運行么
C++和C不同的
如果要在C++里
你前面要寫函數的聲明的
C里就不用

修改過了,試一試吧。
我這里可以
一閃而過那個是圖形界面的問題
驅動沒安裝好

⑻ 10個球如何組成14組,每組5個球

10個球組成14組數巧,每組汪並5個球使用排列組合辦法。編號1,2,3,4,5,6,7,8,9,10得薯陵鍵十個球,5個奇數,5個偶數,5個數全為奇數,這樣的取法有1種,5個數,3個奇數,2個偶數,這樣的取法有C(5,3)*C(5,2)=100,5個數,1個奇數,4個偶數,這樣的取法有C(5,1)*C(5,4)=25,共有126種組合辦法。

⑼ 袋中有10個球,分別有號碼1-10,從中任取3個球,問取出的球最大號碼小於5的概率

取出的球最大號碼小於5的概率1/210。

解:因為從10個球中任取三個球的次數為C(10,3)=840種。

要使取出的球的最大號碼小於5,那麼只能從號碼為1、2、3、4的四個球中任取三個球,

則從號碼為1、2、3、4的四個球中任取三個球的次數為C(4,3)=4種。

所以取出的球最手旦大號碼小於5的概率P=C(3,4)/C(3,10)=4/840=1/210。

即取出的球最大號碼小於5的概率1/210。

(9)十個球源碼擴展閱讀:

1、排列的分類

(1)全排列

從n個不同元素取出m個不同元素的排列中,當m=n時,這個排列稱為全排列。n個元素的全排列的個數記為Pn。

(2)選排列

從n個不同元素取出m個不同元素的差伏排列中,當m<n時,這個排列稱為選排列。n個元素的全排列的個數記為P(m,n)。

2、排虛薯攜列的公式

(1)全排列公式

Pn=n*(n-1)*(n-2)*...*3*2*1=n!

(2)選排列公式

P(m,n)=n*(n-1)*(n-2)*...*(n-m+1)=(n*(n-1)*(n-2)*...*3*2*1)/((n-m)*(n-m-1)*...*3*2*1)

=n!/(n-m)!

參考資料來源:網路-排列組合

參考資料來源:網路-概率

熱點內容
什麼手機安卓系統80 發布:2024-04-20 21:37:29 瀏覽:379
浙江萬里的伺服器地址 發布:2024-04-20 21:16:59 瀏覽:407
ndklinux下載 發布:2024-04-20 21:05:22 瀏覽:566
王者榮耀解壓資源包97 發布:2024-04-20 20:46:10 瀏覽:397
蘋果手機沒有密碼怎麼打開 發布:2024-04-20 20:45:25 瀏覽:93
如何用濃硝酸配置百分之2的硝酸 發布:2024-04-20 20:44:39 瀏覽:797
微信商城java源碼下載 發布:2024-04-20 20:27:35 瀏覽:121
用友軟體sql 發布:2024-04-20 20:10:01 瀏覽:933
python倒著循環 發布:2024-04-20 20:09:52 瀏覽:759
雲伺服器遠程電腦版 發布:2024-04-20 20:09:12 瀏覽:259