當前位置:首頁 » 編程軟體 » 折木棍編程

折木棍編程

發布時間: 2022-05-23 14:48:56

1. c語言編程多少根木棍

問題等價於求a*b>=n且ans=2*(a+b)最小

inta,b,ans;
a=(int)sqrt(n);
if((longlong)a*a>=n)b=a;
elseb=a+1;
if((longlong)a*b<n)a++;
ans=2*(a+b);
printf("%d ",ans);

2. 用C#編寫一個木棍游戲

有空幫你把這個做出來,我還不如加天班,還有加班費拿。。。
你自己做啊,遇到到問題或者沒思路了,過來問個問題還差不多。
感覺難點主要還是AI的設計。

至於 記錄雙方每步走的情況、終結結果,能做到「回放」功能。就比較簡單了,用個List來記錄第幾次拿是誰,拿了幾根就行

3. 一根木棍,把它折成4段要8分鍾.把它折成6段需要幾分鍾

4段 可以折2下,也可以折3下
1.如果是2下,分別每下用時4分鍾
2.如果是3下,分別每下用時8/3分鍾
6段 可以折3下,也可以折4下或者5下
1.3下,12分鍾
4下,16分鍾
5下,20分鍾
2.3下,8分鍾
4下,32/3分鍾
5下,40/3分鍾

4. C++ 拼正方形

首先 題意不明
木棍是否能彎折
木棍是不是必須全部使用
在這
我認為不能彎折
不是必須全部使用
搜索程序
數字不能太大
#include<iostream>
using namespace std;
int m,a[20],v[20];
int d[4];
int f;
void dfs(){//搜索
if(f)return ;
if(d[0]==d[1]&&d[1]==d[2]&&d[2]==d[3]&&d[1]!=0)//是否是答案
{f=1;return ;}
for(int i=0;i<4;i++)
for(int j=0;j<m;j++)//遞歸
if(v[j]==0){
d[i]+=a[j];
v[j]=1;
dfs();
v[j]=0;
d[i]-=a[j];
}
}
int main(){
int n,n1;
cin>>n;
n1=n;//保留n方便輸出
int t[n];
memset(t,0,sizeof(t));//數組變0命令
while(n--){
f=0;
cin>>m;
for(int i=0;i<m;i++)//輸入數據
cin>>a[i];
memset(d,0,sizeof(d));
memset(v,0,sizeof(v));
dfs();
if(f)//記錄
t[n]=1;
else
t[n]=0;

}
for(int i=n1-1;i>=0;i--)//輸出
if(t[i])cout<<"yes\n";
else cout<<"no\n";

system("pause");
}

5. 小木棍 Pascal源程序+題解

program xmugun;

const
maxn=100;

type
xyz=record
x:longint;
y:longint;
end;

var
f:array[-1..3000] of longint;
used:array[-1..maxn] of boolean;
dt:array[-1..maxn] of xyz;
st,hash:array[-1..maxn] of longint;
n,tot,segma,m,up,cp:longint;

procere datain;
var
i,j:longint;
begin
assign(input,'xmugun.in');reset(input);
assign(output,'xmugun.out');rewrite(output);
fillchar(f,sizeof(f),0);
fillchar(hash,sizeof(hash),0);
fillchar(dt,sizeof(dt),0);
segma:=0;
up:=0;
readln(n);
for i:=1 to n do
begin
read(j);
if j>up then up:=j;
segma:=segma+j;
st[i]:=j;
inc(hash[j]);
end;
m:=0;
for i:=1 to maxn do
if hash[i]>0 then
begin
inc(m);
dt[m].x:=i;
dt[m].y:=hash[i];
end;
end;

procere dfs(v0,t,len,jc,last:longint);
var
i,j:longint;
begin
if v0=t+1 then
begin
writeln(jc);
close(input);
close(output);
halt;
end;

if v0>t then exit;
if v0<t then
if not(poss(jc)) then exit;

if len=0 then
for i:=m downto 1 do
if dt[i].y>0 then
break;

if len=0 then
begin
dec(dt[i].y);
if dt[i].x+len<jc then
dfs(v0,t,len+dt[i].x,jc,i) else
begin
dfs(v0+1,t,0,jc,m);
end;
inc(dt[i].y);
end

else

for i:=last downto 1 do
if dt[i].y>0 then
if dt[i].x+len<=jc then
begin
//if dt[i].x+len>jc then break;
dec(dt[i].y);
if dt[i].x+len<jc then
dfs(v0,t,len+dt[i].x,jc,i) else
begin
dfs(v0+1,t,0,jc,m);
end;
inc(dt[i].y);
end;
end;

procere main;
var
i,j:longint;
begin
f[0]:=1;
tot:=0;
for i:=1 to n do
for j:=segma downto 1 do
if j-st[i]>=0 then
if f[j-st[i]]>0 then
f[j]:=1;

for i:=up+1 to segma do
if segma mod i=0 then
if f[i]>0 then
begin
fillchar(used,sizeof(used),true);
dfs(1,segma div i,0,i,m);
end;

end;

begin
datain;
main;
close(input);
close(output);
end.

6. pascal小木棍

program xxx(input,output); var f:array [0..30000] of longint; i,j,k,n,m:longint; n2:longint; p:array [1..200] of longint; sum:longint; ans:boolean; max:longint; flag:boolean; t:longint; begin assign(input,'stick.in'); reset(input); readln(n); for i:=1 to n do begin read(p[i]); sum:=sum+p[i]; if p[i]>max then max:=p[i]; end; close(input); assign(output,'stick.out'); rewrite(output); for i:=1 to n-1 do for j:=i+1 to n do if p[i]>p[j] then begin t:=p[i]; p[i]:=p[j]; p[j]:=t; end; for i:=max+1 to sum div 2 do begin if sum mod i=0 then begin j:=1; k:=n; sum:=p[k]; flag:=true; while j<=k do begin sum:=sum+p[j]; if sum<i then j:=j+1; if sum=i then begin sum:=0; j:=1; k:=k-1; sum:=p[k]; end; if sum>i then begin j:=1; k:=k-1; end; end; if flag then begin writeln(i); close(output); halt; end; end; end; writeln(sum); close(output); end.

滿意請採納

7. 求幫忙,c語言編程編個程序 一個人和電腦 ,20根木棍 ,輪流拿,可以拿1-3個 ,拿到最後一個的輸, 需

#include<stdio.h>
#include<time.h>
#include<windows.h>

voidmain()
{
srand((unsigned)time(NULL));
intPerson;//人
intComputer;//電腦
intSTICK_NUMBER=20;//木棍有20條
intLOSS[2]={0};
while(true)
{
Person=Computer=0;

//人的操作
RESET_PERSON:
printf("[Person]:");
scanf("%d",&Person);
if(Person<1||Person>3)
{
printf("每次取木棍數只限於1~3根,請重新輸入. ");
fflush(stdin);
gotoRESET_PERSON;
}
if(Person>=STICK_NUMBER){
LOSS[0]=1;//人輸了
break;
}
elseSTICK_NUMBER-=Person;

//電腦的操作

printf(" ");
Computer=rand()%(3-1+1)+1;
Sleep(500);
printf("[Computer]:%d",Computer);
if(Computer>=STICK_NUMBER){
LOSS[1]=1;//電腦輸了
break;
}
elseSTICK_NUMBER-=Computer;
fflush(stdin);
printf(" ");

}

if(LOSS[0])printf(" 人輸出了 ");
elseprintf(" 電腦輸出了 ");
}

8. c++ 小木棍標程與解析

#include<iostream>

usingnamespacestd;

intmain(){
inti,N,bar,total=0;
intmax=0;
cin>>N;
for(i=0;i<N;++i){
cin>>bar;
if(bar>0&&bar<50) {
total+=bar;
if(bar>max)max=bar;
}
else--i;
}
while(total%max)++max;
if(max==total)cout<<"拼接失敗 ";
elsecout<<max<<endl;
return0;
}

9. 疊木棍規律

10次是2的10次方=1024根
n次是2的n次方根

10. 一根1m的木棍,隨機折成兩截,選長的再隨機折成兩截,問構成三角形的概率

設第一次折成的兩截中第一部分的長度為ξ,則第二部分的長度為1-ξ

第二次折成的兩截中第一部分的長度為η

1.當ξ≤1-ξ時,第二次折成的兩截中第二部分的長度為1-ξ-η

要構成三角形,必須滿足ξ+η>1-ξ-η,ξ+(1-ξ-η)>η,η+(1-ξ-η)>ξ

即ξ<1/2,1/2-ξ<η<1/2

當ξ=x,0<x<1/2時,η~U[0,1-x]

η的密度函數為f(y)=1/(1-x),0≤y≤1-x

f(y)=0, 其他

2.若ξ≥1-ξ,第二次折成的兩截中第二部分的長度為ξ-η

要構成三角形,必須滿足ξ>1-ξ,η+(1-ξ)>ξ-η,(ξ-η)+(1-ξ)>η

即ξ>1/2,ξ-1/2<η<1/2

當ξ=x,1/2<x<1時,η~U[0,x]

η的密度函數為f(y)=1/x,0≤y≤x

f(y)=0, 其他

熱點內容
java返回this 發布:2025-10-20 08:28:16 瀏覽:705
製作腳本網站 發布:2025-10-20 08:17:34 瀏覽:968
python中的init方法 發布:2025-10-20 08:17:33 瀏覽:676
圖案密碼什麼意思 發布:2025-10-20 08:16:56 瀏覽:828
怎麼清理微信視頻緩存 發布:2025-10-20 08:12:37 瀏覽:737
c語言編譯器怎麼看執行過程 發布:2025-10-20 08:00:32 瀏覽:1076
郵箱如何填寫發信伺服器 發布:2025-10-20 07:45:27 瀏覽:308
shell腳本入門案例 發布:2025-10-20 07:44:45 瀏覽:188
怎麼上傳照片瀏覽上傳 發布:2025-10-20 07:44:03 瀏覽:875
python股票數據獲取 發布:2025-10-20 07:39:44 瀏覽:829