4-5 报数 (20分)
来源:互联网 发布:windows 2008 r2 编辑:程序博客网 时间:2024/04/30 05:39
4-5 报数 (20分)
报数游戏是这样的:有n个人围成一圈,按顺序从1到n编好号。从第一个人开始报数,报到m(<n)的人退出圈子;下一个人从1开始报数,报到m的人退出圈子。如此下去,直到留下最后一个人。
本题要求编写函数,给出每个人的退出顺序编号。
函数接口定义:
void CountOff( int n, int m, int out[] );
其中n
是初始人数;m
是游戏规定的退出位次(保证为小于n的正整数)。函数CountOff
将每个人的退出顺序编号存在数组out[]
中。因为C语言数组下标是从0开始的,所以第i
个位置上的人是第out[i-1]
个退出的。
裁判测试程序样例:
#include <stdio.h>#define MAXN 20void CountOff( int n, int m, int out[] );int main(){ int out[MAXN], n, m; int i; scanf("%d %d", &n, &m); CountOff( n, m, out ) for ( i = 0; i < n; i++ ) printf("%d ", out[i]); printf("\n"); return 0;}/* 你的代码将被嵌在这里 */
输入样例:
11 3
输出样例:
4 10 1 7 5 2 11 9 3 6 8
//
void CountOff(int n,int m,int out[]){ for(int i=0;i<n;i++) out[i]=0; int counter,location,tocal; location=0; for(tocal=1;tocal<=n;tocal++) { counter=0; while(counter<m) { if(out[location]==0) counter++; if(counter==m) out[location]=tocal; location=(location+1)%n; } }}
0 0
- 4-5 报数 (20分)
- 5-4 jmu-报数游戏 (15分)
- 习题8-4 报数
- 报数
- 报数
- 报数
- 报数
- 报数
- 报数
- 报数
- 报数
- 报数
- 报数
- 报数
- 报数
- C。习题八。三。4(报数)
- 专家分5分
- 5-24 藏尾诗 (20分)
- 排序算法 之 插入排序InsertionSort
- Ubuntu下slickedit的安装与配置
- 改HTML5里的input标签的required属性的提示为英文的
- POJ 1740 A New Stone Game【博弈】
- java之生产者消费者模式
- 4-5 报数 (20分)
- 欢迎使用CSDN-markdown编辑器
- Swift-常量与变量
- tjut 1159
- GZIP压缩原理分析(25)——第五章 Deflate算法详解(五16) 动态哈夫曼编码分析(05) LZ77过程(04)
- 最近遇到了一些事
- 让CORTANA实现关机,打开你想要打开的应用程序
- iframe标签之父子元素互访
- matlab plotly可视化