ACM试题及答案2文档格式.docx
- 文档编号:18195258
- 上传时间:2022-12-14
- 格式:DOCX
- 页数:22
- 大小:21.04KB
ACM试题及答案2文档格式.docx
《ACM试题及答案2文档格式.docx》由会员分享,可在线阅读,更多相关《ACM试题及答案2文档格式.docx(22页珍藏版)》请在冰豆网上搜索。
i++)
j=0;
j<
a[i].num;
j++)
p=1;
temp+=a[i].weight;
x=0;
x<
m;
x++)
if(temp==w[x])
p=0;
}
if(p)
w[m]=temp;
m++;
return
void
main()
n=0;
scanf("
%d"
&
n);
i=0;
%d%d"
fama1[i].weight,&
fama1[i].num);
maxnum=0;
for(i=0;
maxnum+=count(fama1,i,n);
printf("
%d\n"
maxnum);
座位调整
2006年XX之星程序设计大赛初赛题目5
座位调整
题目描述:
XX办公区里到处摆放着各种各样的零食。
XX人力资源部的调研发现,员工如果可以在自己喜欢的美食旁边工作,工作效率会大大提高。
因此,XX决定进行一次员工座位的大调整。
调整的方法如下:
1.首先将办公区按照各种零食的摆放分成N个不同的区域。
(例如:
可乐区,饼干区,牛奶区等等)。
2.每个员工对不同的零食区域有不同的喜好程度(喜好程度度的范围为1—100的整数,喜好程度越大表示该员工越希望被调整到相应的零食区域)。
3.由于每个零食区域可以容纳的员工数量有限,人力资源部希望找到一个最优的调整方案令到总的喜好程度最大。
数据输入:
第一行包含两个整数N,M,(1<
=N,M<
=300)。
分别表示N个区域和M个员工。
第二行是N个整数构成的数列a,其中a[i]表示第i个区域可以容纳的员工数,(1<
=a[i]<
=M,a[1]+a[2]+..+a[N]=M)。
紧接着是一个M*N的矩阵P,P(i,j)表示第i个员工对第j个区域的喜好度。
答案输出:
对于每个测试数据,输出可以达到的最大的喜好程度。
输入样例
33
111
1005025
输出样例
175
stdlib.h>
b[302][302];
i,r,j,k=0,sum=0,n,m,l,s;
n,&
m);
for(i=1;
=n;
b[0][i]);
=m;
for(j=1;
b[i][j]);
for(l=1;
l<
l++)
if(k<
b[l][j])
k=b[l][j];
r=j;
sum+=k;
b[0][r]--;
k=0;
if(b[0][r]==0)
for(s=1;
s<
s++)
b[s][r]=0;
}
sum);
system("
pause"
);
0;
大足球比赛
吉林一中将举办一年一度的足球比赛。
Andy的班级即将面临一组强队,就是去年的冠军队。
Andy在比赛之前做了充分的准备,搜集了许多关于这支队伍的信息。
在这支队伍中有N-1个队员,通过过去比赛记录来看,他们总是在某些固定的队员之间传球。
我们把对方的守门员编号为1号,我们的球门编号为N号,其他的为对方球员。
资料里给出若干个整数对(ai,bi),表示球会从ai传到bi,如果ai==1,代表球从对方守门员开出,如果bi==N,代表球攻入我方大门。
其他情况均为对方队友间的传球配合。
每组传球,还会给出一个实数pi,表示对方传球成功的概率,我方成功防守的概率就是1-pi。
我们会选择一些对方的传球路线做重点防御,使得不会出现某条从对方守门员到我方大门路径完全没有防守。
假设我们选取的防御集合为S,我们定义了估价函数F(S)表示该种防守的可靠值。
现在你需要计算这个可靠值最大值。
输入
输入包含多组测试数据。
数据的第一行包含两个整数N,M(1<
=N<
=100,1<
=M<
=400),接下来M行,每行包含三个数字aibiPi(1<
=ai,bi<
=N,0<
=Pi<
=1).
输入文件结束于N=M=0.
输出
对于每组数据,如果最大值为0,输出“Theopponentistoostrong!
”如果最大值为1,输出“Theopponentistooweek!
”,否则输出这个最大值,保留6位小数。
样例输入
44
120.5
240.6
230.5
340.8
121.0
231.0
341.0
241.0
120
00
样例输出
0.500000
Theopponentistoostrong!
Theopponentistooweek!
#include
<
algorithm>
iostream>
assert.h>
memory>
utility>
vector>
functional>
math.h>
numeric>
using
namespace
std;
#define
MAX_PLAYER
101
MAX_PASS
401
START_PLAYER
MARK_VALUE
(-1)
end;
//to
be
n+1;
m,n;
_Node
in[MAX_PLAYER];
float
in_f[MAX_PLAYER];
};
_Node
nodes[MAX_PLAYER];
bool
isMin(pair<
int,int>
&
a,pair<
b)
nodes[a.second].in_f[a.first]
nodes[b.second].in_f[b.first];
inline
ReadAndFill(FILE
*file)
a,b;
f;
i=m;
while(i--
>
0)
fscanf(file,"
%d
%f\n"
a,&
b,&
f);
++nodes[b].in[a];
//there
is
a
path
from
a-->
b
nodes[b].in_f[a]
=
//the
cost
b
store
here
//printf("
a,b,f);
_ResolvePath(vector<
pair<
path,int
level,int
start)
path.push_back(make_pair(start,level));
s
START_PLAYER;
while
(1)
*r
find_if(nodes[start].in+s,
nodes[start].in+end,
bind2nd(greater<
int>
(),0));
if(r
==
nodes[start].in+end)
break;
index
((int)r
-
(int)&
nodes[start].in)
/
sizeof(int);
_ResolvePath(path,start,index);
+
1;
ResolvePath(vector<
float>
toDefence)
vector<
path;
start
find_if(nodes[n].in+start,
nodes[n].in+end,
nodes[n].in+end)
nodes[n].in)
_ResolvePath(path,n,index);
*p
min_element(path.begin(),path.end(),isMin);
p->
first;
to
second;
if(nodes[to].in[from]
MARK_VALUE)
//We
have
add
this
path.
else
toDefence.push_back(nodes[to].in_f[from]);
nodes[to].in[from]
MARK_VALUE;
//pseudocode:
//while
n
m
!
//do
//ReadAndFill
//Resolve
every
path,make
smallest
in
the
as
marked.
//output
//end
FILE
*f
fopen("
data.dat"
"
rb"
assert(f);
//we
temp
here
and
get
toDefence;
//for
calculation
fscanf(f,"
do{
end
ReadAndFill(f);
ResolvePath(toDefence);
i;
/*
size=%d\n"
toDefence.size());
toDefence.size();
++i)
%.6f"
toDefence[i]);
*/
beforePow
*=
(1-toDefence[i]);
output
pow(beforePow,(float)1
(float)toDefence.size());
if(output
The
opponent
too
strong!
\n"
else
if
(output
1)
week!
%.6f\n"
output);
toDefence.clear();
}while(n
0);
母牛生小牛
设有一头小母牛,从出生第四年起每年生一头小母牛,按此规律,第N年时有几头母牛?
本题有多组数据。
每组数据只有一个整数N,独占一行。
(1≤N≤50)
对每组数据,输出一个整数(独占一行)表示第N年时母牛的数量
4
20
3
872
f(int
years=0;
cout<
"
请输入年数!
endl;
cin>
years;
total
of
cow
are
:
f(years)<
//使用循环递归,每个递归返回其自身的子系(父子关系
,包括它自己)数量,
//for循环里为同一子代(兄弟关系)
if(n==1||n==2||n==3)
sum=1,nl=n-3;
for(nl;
nl>
--nl)
sum+=f(nl);
sum;
SortingItAllOut
Description
Anascendingsortedsequenceofdistinctvaluesisoneinwhichsomeformofaless-thanoperatorisusedtoordertheelementsfromsmallesttolargest.Forexample,thesortedsequenceA,B,C,DimpliesthatA<
B,B<
CandC<
D.inthisproblem,wewillgiveyouasetofrelationsoftheformA<
Bandaskyoutodeterminewhetherasortedorderhasbeenspecifiedornot.
Inputconsistsofmultipleprobleminstances.Eachinstancestartswithalinecontainingtwopositiveintegersnandm.thefirstvalueindicatedthenumberofobjectstosort,where2<
=n<
=26.Theobjectstobesortedwillbethefirstncharactersoftheuppercasealphabet.ThesecondvaluemindicatesthenumberofrelationsoftheformA<
Bwhichwillbegiveninthisprobleminstance.Nextwillbemlines,eachcontainingonesuchrelationconsistingofthreecharacters:
anuppercaseletter,thecharacter"
andaseconduppercaseletter.Noletterwillbeoutsidetherangeofthefirstnlettersofthealphabet.Valuesofn=m=0indicateendofinput.
Foreachprobleminstance,outputconsistsofoneline.Thislineshouldbeoneofthefollowingthree:
Sortedsequencedeterminedafterxxxrelations:
yyy...y.
Sortedsequencecannotbedetermined.
Inconsistencyfoundafterxxxrelations.
wherexxxisthenumberofrelationsprocessedatthetimeeitherasortedsequenceisdeterminedoraninconsistencyisfound,whichevercomesfirst,andyyy...yisthesorted,ascendingsequence.
46
A<
B
C
B<
C<
D
32
A
261
Z
Sortedsequencedeterminedafter4relations:
ABCD.
Inconsistencyfoundafter2relations.
Sortedsequencecannotbedetermined.
MAX_SIZE
26
destruct(bool
**result,char
*rr,bool
*status,int
M);
//void
construct(bool
M,N;
M>
N;
//输入规模
**result;
i,j,k;
char
small;
large;
*rr;
*status;
result=new
*[M];
for
(i=0;
M;
result[i]=new
bool[M];
//initial
matrix
(j=0;
result[i][j]=false;
rr=new
char[M];
status=new
status[i]=false;
length=0;
flag;
i++)//输入数据
small>
large>
result[small-'
A'
][l
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- ACM 试题 答案