【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

写个数组模拟链表
但注意,得用个辅助数组flag。。
不然可能会出现没能跳过中间的被占区域的情况。
比如
1 2 idx # # # idx2 8
(#表示已经出去的位置)
这个时候,idx1和idx2删掉的话。(假设先删idx1,后删idx2)
r[idx1]无法更新为8。。

【代码】

#include <bits/stdc++.h>
using namespace std; const int N = 20; int n,m,k; int l[N+10],r[N+10];
int flag[N+10]; void _delete(int idx){
int L = l[idx],R = r[idx];
r[L] = R;
l[R] = L;
} void step_left(int *x){
*x = l[*x];
while (flag[*x]) *x =l[*x];
} void step_right(int *x){
*x = r[*x];
while (flag[*x]) *x=r[*x];
} int main()
{
//freopen("/home/ccy/rush.txt","r",stdin);
ios::sync_with_stdio(0),cin.tie(0);
while (cin >> n >> k >> m){
memset(flag,0,sizeof flag);
if(n==0 && m==0 && k==0) break;
int idx1 = 1,idx2 = n;
for (int i = 1;i <= n;i++) l[i] = i-1,r[i]=i+1;
l[1] = n;r[n] = 1;
int cnt = n;
while (cnt>0){
for (int i = 1;i <= k-1;i++) step_right(&idx1);
for (int i = 1;i <= m-1;i++) step_left(&idx2);
if (idx1==idx2){
_delete(idx1);
cnt--;
cout<<setw(3)<<idx1;
}else{
_delete(idx1);_delete(idx2);
while (flag[idx1]) idx1 = r[idx1];
while (flag[idx2]) idx2 = l[idx2];
cnt-=2;
cout<<setw(3)<<idx1<<setw(3)<<idx2;
}
flag[idx1] = flag[idx2]=1;
if (cnt==0) {
cout<<endl;
break;
}else cout<<",";
step_right(&idx1);step_left(&idx2);
}
}
return 0;
}

【例题4-3 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(成环状态下的循环走步方法)

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

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

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

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

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

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

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

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

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

  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 ...

  10. The Dole Queue

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

随机推荐

  1. OpenCV:Visual Studio 2013 Ultimate中OpenCV 2.4.8 配置

    配置环境: 操作系统:Win8.1  64位 IDE平台:Visual Studio 2013 Ultimate 一.准备OpenCV 2.4.8 1.下载:从官网下载 OpenCV2.4.8:   ...

  2. Android将图像转换成流存储与将流转换成图像

    1.将图片转换成二进制流 public byte[] getBitmapByte(Bitmap bitmap){ ByteArrayOutputStream out = new ByteArrayOu ...

  3. elasticsearch 分页查询实现方案——Top K+归并排序

    elasticsearch 分页查询实现方案 1. from+size 实现分页 from表示从第几行开始,size表示查询多少条文档.from默认为0,size默认为10,注意:size的大小不能超 ...

  4. PCB 线路板人生

    由此开端,增加PCB人生分类栏,后续在此分享PCB 非工作方面所思所想,由于文笔不好,请指正.

  5. E20170905-mk

    recursive   adj. 回归的,递归的;

  6. go的基础数据类型

    一.基础数据类型 在go语言中,数据类型用于申明函数和变量 go语言的类型 数据类型 描述 布尔型 布尔型值的只能是true 和 false ,例如 var b bool = true, 布尔型值声明 ...

  7. Cracking the Coding Interview 6.5

    There is a building of 100 floors. If an egg drops from the Nth floor or above, it will break. If it ...

  8. 题解报告:hdu 4764 Stone(巴什博弈)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4764 Problem Description Tang and Jiang are good frie ...

  9. C#之单列双列集合绑定数据

    ---恢复内容开始--- 1.单列集合绑定方式 davList.DataSource=new BindingList<类型名>(集合名); 2.双列集合绑定方式 BindingSource ...

  10. Spring Boot (13) druid监控

    druid druid是和tomcat jdbc一样优秀的连接池,出自阿里巴巴.除了连接池,druid哈hi有一个很实用的监控功能. pom.xml 添加了以下依赖后,会自动用druid连接池替代默认 ...