皮带秤标定精度:取数游戏

来源:百度文库 编辑:中科新闻网 时间:2024/05/09 04:02:01
有一个游戏,在一块板上写着一行数,共n个 。两个游戏者,轮流从最右或最左取一个数。刚开始,每个游戏者的 得分均为零。如果一个游戏者取下一个数,则将该数的值加到该游戏 者的得分上,最后谁的得分最高谁就赢了游戏。给出这n个数( 从 左往右), 假设游戏者都是非常聪明的,问最后两个人的得分(假 设第一个人首先取数).
输入格式:第一行为n(2< ;
=n<
=100),第二行为n个数,每个数字之间均用空 格隔开。输出为两个游戏者的得分.第一个数表示第一个游戏者的得 分,第二个数为第二个游戏者的得分,两个数字之间用空格隔开。< br>如输入
6
4 7 2 9 5 2
输出
18 11/* Copyright (c) ap rin at Xiamen University 2005- 04 * */#include <
stdio.h> ;
#define MAXN 100int sum(int d ata[], int head, int tail);
int best(int data[], int head, in t tail) { int temp1, temp2;
if(head==tail) return head;
temp1= *(data+head)+sum(data , head+1, tail);
temp2= *(dat a+tail)+sum(data, head, tail-1 );
return (temp1>
temp2)?he ad:tail;
/*返回指针*/}int sum(int d ata[], int head, int tail) { int temp;
if(head==tail) r eturn 0;
/*有0个数据*/ if(tail== h ead+1) return (*(data+head) <
*(data+tail))?head:tail;
/* 取小的那一个*/ if(best(data, head, tail)==head)/*改变工作指针,让对方选一个最好值 */ head++;
else tail--;
t emp= best(data, head, tail);
if(temp==head) return *(dat a+temp)+sum(data, head+1, tail );
else return *(data+temp )+sum(data, head, tail-1);
}int main(void) { int data[MAXN], head, tail, n, i, total1, tot al2, temp;
scanf("
%d&quo t;
, &
n);
while((n<
2)|| (n>
100)) { printf("
N is wrong! Please input n(2&l t;
=n<
=100) again!\n"
);
scanf("
%d"
, & ;
n);
} for(i=0;
i<
n;
i++) scanf("
%d"
, data +i);
total1= total2= 0;
head =0;
tail= n-1;
for(i=0;
i< ;
n;
i++) { temp= best(data, head, tail);
if((i+1)%2!=0 ) total1= total1+*(data+t emp);
else total2= tot al2+*(data+temp);
if(temp== head) head= head+1;
el se tail= tail-1;
} prin tf("
%d %d\n"
, total1 , total2);
getch();
return 0 ;
}

不知该怎么编程,还请各位大虾指教!具体用什么语言,具体怎么编,如果有编好的发给我,那就最好拉,先感谢了!!!
麻烦大虾把编这个数字游戏的编程软件的网址上传

把编好的游戏发给我

晕,你连编程的语言都不知道,那还怎么教你呢?

只能说:用pascal,动态规划算法。

我不知道,难