折木棍编程
问题等价于求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, 其他

