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

【题意】

在这里输入题意

【题解】

写个数组模拟链表
但注意,得用个辅助数组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. Codeforces Round #257 (Div. 2/B)/Codeforces450B_Jzzhu and Sequences

    B解题报告 算是规律题吧,,,x y z -x -y -z 注意的是假设数是小于0,要先对负数求模再加模再求模,不能直接加mod,可能还是负数 给我的戳代码跪了,,. #include <ios ...

  2. Extjs显示图片

    1.首先做一个容器 xtype : 'container', // 第2行 anchor : '100%', layout : 'column', items : [{ columnWidth : 0 ...

  3. DockPanelSuite中的DocumentStyle

    首先明确一个概念Mdi的完整词组:Multiple document interface namespace WeifenLuo.WinFormsUI.Docking { public enum Do ...

  4. tflearn中计算混淆矩阵方法——需要经过一步转换

    def do_rnn_wordbag(trainX, testX, trainY, testY): y_test=testY #trainX = pad_sequences(trainX, maxle ...

  5. 【BZOJ 2288】 生日礼物

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=2288 [算法] 先将这个序列的正负数合并起来,变成一个正负交替的序列 如果新序列的正 ...

  6. 机器人走迷宫(dfs)

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1590 #include <stdio.h ...

  7. hdu3507Print Article(斜率优化dp)

    Print Article Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)To ...

  8. EasyUI TreeGrid 悬浮效果

    /* 鼠标悬停扩展*/ (function (hasgrid) { if (hasgrid) { /** * 表格提示 */ $.extend($.fn.datagrid.methods, { too ...

  9. 深入理解Redis(番外)——持久化

    引语 Redis作为一款内存数据库,自然所有数据都加载在内存中,那么自然就有小伙伴会问,如果服务器宕机了怎么办,数据不都丢了吗,不用担心,Redis早就提供了两种方式来将数据进行持久化,即便服务器宕机 ...

  10. Spring Boot (9) mybatis全注解化

    ORM对比图 框架对比 Spring JDBC Spring Data Jpa Mybatis 性能 性能最好 性能最差 居中 代码量 多 少 多 学习成本 低 高 居中 推荐指数 ❤❤❤ ❤❤❤❤❤ ...