类型:循环走步

 #include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <cctype>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <map>
#include <stack>
#include <list>
#include <iomanip> using namespace std; #define INF 0x7fffffff
#define maxn 1010
typedef unsigned long long ull; int arr[maxn];
int N, k, m; //d也能表示顺时针还是逆时针,顺时针-1,逆时针1
//注意此处的算法
int go(int t, int p, int d)
{
33 while(t--)
34 {
35 do{
36 ///
37 p = (p+d+N-1)%N+1;
38 }
39 while(!arr[p]);
40 }
return p;
} int main()
{
while(scanf("%d%d%d", &N, &k, &m) && (N+k+m))
{
memset(arr, , sizeof(arr));
for(int i = ; i <= N; i++)
arr[i] = i; 52 int left = N;//剩下的人数
53 int p1 = 0, p2 = N+1;//位置标记 while(left)
{
p1 = go(k, p1, );
p2 = go(m, p2, -);
arr[p1] = arr[p2] = ;
//注意此处的输出优化
printf("%3d", p1); left--;
if(p1 != p2)
{
printf("%3d", p2); left--;
}
if(left) printf(",");
else printf("\n");
}
}
return ;
}

uva - 133 The Dole Queue(成环状态下的循环走步方法)的更多相关文章

  1. UVA 133 The Dole Queue

    The Dole Queue 题解: 这里写一个走多少步,返回位置的函数真的很重要,并且,把顺时针和逆时针写到了一起,也真的很厉害,需要学习 代码: #include<stdio.h> # ...

  2. uva 133 The Dole Queue 双向约瑟夫环 模拟实现

    双向约瑟夫环. 数据规模只有20,模拟掉了.(其实公式我还是不太会推,有空得看看) 值得注意的是两个方向找值不是找到一个去掉一个,而是找到后同时去掉. 还有输出也很坑爹! 在这里不得不抱怨下Uva的o ...

  3. UVA 133“The Dole Queue”(循环报数处理技巧)

    •参考资料 [1]:紫书P82 •题意(by紫书) 按照被选中的次序输出这 n 个人的编号: 如果A和B选中的是同一个人,输出一个这个人的编号: 输出格式:输出的每个编号占3个字节,不够3个字节在前面 ...

  4. UVA 133 The Dole Queue(报数问题)

    题意:一个长度为N的循环队列,一个人从1号开始逆时针开始数数,第K个出列,一个人从第N个人开始顺时针数数,第M个出列,选到的两个人要同时出列(以不影响另一个人数数),选到同一个人就那个人出列. 思路: ...

  5. uva 133(The Dole Queue UVA - 133)

    一道比较难想的模拟题,用了队列等东西,发现还是挺难做的,索性直接看了刘汝佳的代码,发现还是刘汝佳厉害! 代码本身难度并不是很大,主要还是p=(p+n+d-1)%n+1;这一句有些难度,实际上经过自己的 ...

  6. uvaoj 133 - The Dole Queue(逻辑,环形队列数数)

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  7. C语言中关于POW在不同状态下四舍五入的解决方法

    这是今天作业中的一个代码: #include <stdio.h>#include<math.h>int main(){ printf("请输入一个整数:") ...

  8. UVa133.The Dole Queue

    题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  9. The Dole Queue UVA - 133

     In a serious attempt to downsize (reduce) the dole queue, The New National Green Labour Rhinoceros ...

随机推荐

  1. NGUI如何创建自己的精灵图集

    说实话其实很简单,但是在不知道的情况下真的不好弄啊. 1. 选择你要制作精灵图集的图片,可以选择多张 2. 提倡使用快捷键Alt + Shift + M 会有如下窗口弹出,也可以NGUI --> ...

  2. Flash 导出图片和声音

    命令文件 PolarBear_jsfl.zip Flash Professional 编辑器命令,用来导出 flash 库中的图片和声音 使用步骤: 1. 首先下载 PolarBear_jsfl.zi ...

  3. 【opencv】图像细化

    [原文:http://blog.csdn.net/qianchenglenger/article/details/19332011] 在我们进行图像处理的时候,有可能需要对图像进行细化,提取出图像的骨 ...

  4. STM32软件仿真的一个注意点

    最近才做的板子由于自己的粗心把串口线搞反了,还好只有两条,飞线解决,而且现在还只是样板,但是还是应该引以为戒,以后做硬件一定要谨慎. 今天同事出差把CAN分析仪拿走了,本来在开发板上调试好的程序不知为 ...

  5. [九度OJ]1078.二叉树的遍历(重建)

    原题链接:http://ac.jobdu.com/problem.php?pid=1078 题目描述: 二叉树的前序.中序.后序遍历的定义:前序遍历:对任一子树,先访问跟,然后遍历其左子树,最后遍历其 ...

  6. bzoj 1058 [ZJOI2007]报表统计(set)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1058 [题意] 一个序列,提供插入,查询相邻最小差值,查询任意最小差值的操作. [思路 ...

  7. rtems总结

    rtems 历史背景及现状 常用的api 和参数介绍 rtems_interrupt_enable rtems_interrupt_is_in_progress rtems_cache_flush_r ...

  8. HW6.7

    public class Solution { public static void main(String[] args) { int[] count = new int[10]; int numb ...

  9. EXCEL 建立工作薄与工作表

    //1.引用单元 uses ComObj; //2.建立工作薄与工作表 procedure TForm1.Button1Click(Sender: TObject); Var ExcelApp,She ...

  10. 基于UDP协议的多路广播地址

    因为多路广播地址的范围是224.0.0.0 到239.255.255.255之间,所以我们可以从中取一个地址给我们的程序用即可