The Dole Queue

题解:

这里写一个走多少步,返回位置的函数真的很重要,并且,把顺时针和逆时针写到了一起,也真的很厉害,需要学习

代码:

#include<stdio.h>
#define maxn 25
int n, k, m, a[maxn]; int go(int p,int d,int t)
{
while(t--){
do{p=(p+d-1+n)%n+1;}while(a[p]==0);
}
return p;
} int main()
{
while(scanf("%d%d%d", &n, &k, &m) == 3 && n) {
for(int i = 1; i <= 20; i++)a[i] = i;
int left = n;
int p1 = n, p2 = 1;
while(left) {
p1=go(p1,1,k);
p2=go(p2,-1,m);
printf("%3d",p1),left--;
if (p1!=p2) printf("%3d",p2),left--;
a[p1]=a[p2]=0;
if (left)printf(",");
}
puts("");
}
return 0;
}

UVA 133 The Dole Queue的更多相关文章

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

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

  2. uva - 133 The Dole Queue(成环状态下的循环走步方法)

    类型:循环走步 #include <iostream> #include <sstream> #include <cstdio> #include <cstr ...

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

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

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

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

  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. UVa133.The Dole Queue

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

  8. The Dole Queue UVA - 133

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

  9. The Dole Queue

    The Dole Queue Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit cid ...

随机推荐

  1. POJ 1321 棋盘问题 --- DFS

    POJ 1321 题目大意:给定一棋盘,在其棋盘区域放置棋子,需保证每行每列都只有一颗棋子. (注意 .不可放 #可放) 解题思路:利用DFS,从第一行开始依次往下遍历,列是否已经放置棋子用一个数组标 ...

  2. __attribute__你知多少(转)

    转自:http://www.cnblogs.com/astwish/p/3460618.html GNU C 的一大特色就是__attribute__ 机制.__attribute__ 可以设置函数属 ...

  3. LVM磁盘管理

    http://www.cnblogs.com/gaojun/archive/2012/08/22/2650229.html Linux LVM硬盘管理及LVM扩容 LVM磁盘管理 一.LVM简介... ...

  4. Unable to determine the principal end of an association between the types '***. The principal end of this association must be explicitly configured using either the relationship fluent API or data annotations.

    MVC中数据库表如果是一对一的主键关系时要加[Required]不然会出错Unable to determine the principal end of an association between ...

  5. window.parent与window.openner

    window.parent与window.openner区别介绍 作者: 字体:[增加 减小] 类型:转载 今天总结一下js中几个对象的区别和用法,对这几个概念混淆的朋友可以看看 今天总结一下js中几 ...

  6. struts2 的简单实例应用

    功能:本实例实现的功能是从输入界面输入用户名和密码,若用户名和密码正确转到成功界面,否则转到失败界面. 1)在创建了一个JavaWeb工程后,导入struts2的核心支持包库. 2)web项目右击-M ...

  7. httpd-2.2

    http://httpd.apache.org/docs/2.2/logs.html httpd.conf文件 Configuration and logfile names: If the file ...

  8. sqlserver模糊查询【转】

    http://blog.csdn.net/liuxinxin1125/article/details/5444873 SELECT * FROM user WHERE name LIKE ';%三%' ...

  9. Problem A+B(Big Integer)

    /*======================================================================== Problem A+B(Big Integer) ...

  10. net cookie操作

    写入方法: HttpCookie cookie = new HttpCookie("id"); cookie.Value=cookieValue; cookie.Expires = ...