| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1063 人关注过本帖
标题:求这一道编程题答案
只看楼主 加入收藏
丰田甜
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2018-4-18
结帖率:100%
收藏
已结贴  问题点数:10 回复次数:1 
求这一道编程题答案

Three players, A, B, and C play a dice game, each player rolls two dice.

(The points of 2*3 = 6 dice should be set and stored in advance)

PART I:

Assume that each player can only see the points of his/her own two dice, simulate their game process.

Rules of PART I:

Starting from player A, the following steps are performed in turn.

First, the two dice thrown by the player A are output (indicating that A sees his/her dice), and then two numbers a and b are required to be input to represent A's guess for all dice, which means the number of b point dices in total is at least a.

Then it's the next player B's turn. After seeing his own dice, B can choose to enter 0 0 (two zeros) for "I don't believe" or to enter a new pair of numbers c and d, which means he/she guesses "there are at least c d points in all dice", where c,d must satisfy c≥a, and when c=a, d>b.

The game continues until someone input 0 0 (two zeros).

Optional rules:1 point dice can be regarded as any number of points.

For example:

O: A's turn: A has 2 and 1
I: 2 4
O: B's turn: B has 3 and 2
I: 2 3
O: Invalid input.
O: B's turn: B has 3 and 2
I: 3 2
O: C's turn: C has 2 and 5
I: 3 5
O: A's turn: A has 2 and 1
I: 4 2
O: B's turn: B has 3 and 2
I: 0 0

If someone (let's say player B above) enters 0 0 (two zeros), then show all 2 * 3 = 6 dice, determine the current player's "unbelieving" is right or wrong to judge the loser of the game: Assume that the previous player's input is x y. If the number of dice in y points is less than x (in a total of 6 dice), then the previous player (A) loses, otherwise, the current player (B) loses.

For example:

O: A's turn: A has 2 and 1
I: 2 4
O: B's turn: B has 3 and 2
I: 2 3
O: Invalid input.
O: B's turn: B has 3 and 2
I: 3 2
O: C's turn: C has 2 and 5
I: 3 5
O: A's turn: A has 2 and 1
I: 4 2
O: B's turn: B has 3 and 2
I: 0 0
O: All dices: 2 1 3 2 2 5
Loser is A. (Without optional rules)

Loser is B. (With optional rules)



PART II:

Play this game from the perspective of God, i.e. you can see all of the 6 dice.

Rules of PART II:

Observe all 6 dice and output the optimal combination of a and b, which means it  will certainly  be wrong for any other player to guess again.

For example:

O: All dices: 2 1 3 2 2 5
Best answer: 3 2 (Without optional rules)

Best answer: 4 2 (With optional rules)

注:

O: 用例输出,I: 用例输入,不必写在程序输出里

要求体现代码的良好风格、友好界面、算法和代码的高执行效率等。

其他可选部分:例如,可选择2-5之间的数字作为游戏人数及骰子个数等。

开放时间:    2018年04月02日 星期一 12:00
截止时间:    2018年04月21日 星期六 00:00
上传一个文件
跳过 导航
导航
我的主页
搜索更多相关主题的帖子: player and the for input 
2018-04-18 15:03
nosnoy
Rank: 9Rank: 9Rank: 9
来 自:mcu
等 级:贵宾
威 望:14
帖 子:541
专家分:1178
注 册:2016-9-17
收藏
得分:10 
我的天 出题者酒吧老手啊  

其实这个不是很难吧

//生成随机1-6的整数
int shaizi(){
int r;
 srand(time(NULL));
 r=rand()%6+1;
 return r;
}
//生成每个人的骰子
void enyshaizi()
{
for(int i=0;i<n;i++)
{
    a[i][0]=shaizi();
}
}
//存储最大值
void max_number()
{
    for(int i=0;i<n;i++)
    for(int j=0;j<2;j++)
    switch(a[i][j])
        {
        case 1: maxx[0]++;break;
        ~~~~~~~~
        }

}
//判断
int panduan(int x,int y)
{
    if(x>max[y-1])return 0;
    else return 1;
}
void shuru()
{
while(1)
{
    int i=0
 scanf("%d%d",&x,&y);
     if(x==0&y==0)
      {
        i=panduan(m,n);
        return i;
        break;
        }
        
      if(n>=y&&m>=x)
    printf("无效输入");
    else
    {
     m=x;
     n=y;
    }
    if(x==0&y==0){
}

}
void main()
{ int n=0;
int maxx[6]={0};
int a[5][2];
char name[5];

while(scanf("%c",&name[n])!=-1)
 n++;
enyshaizi();
max_number();
shuru();
剩下的你自己写下
}





穷举是最暴力的美学
2018-04-18 17:28
快速回复:求这一道编程题答案
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.022728 second(s), 11 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved