In a serious attempt to downsize (reduce) the dole queue, The New National Green Labour Rhinoceros Party has decided on the following strategy. Every day all dole applicants will be placed in a large circle, facing inwards. Someone is arbitrarily ch…
n(n<20)个人站成一圈,逆时针编号为1-n.有两个官员,A从1开始逆时针数,B从n开 始顺时针数.在每一轮中,官员A数k个就停下来,官员B数m个就停下来(注意有可能两个 官员停在同一个人上).接下来被官员选中的人(1个或者2个)离开队伍. 输入n,k,m输出每轮里被选中的人的编号(如果有两个人,先输出被A选中的).例 如,n=10,k=4,m=3,输出为4 8, 9 5, 3 1, 2 6, 10, 7.注意:输出的每个数应当恰好占3列. #include<stdio.h> #def…
一道比较难想的模拟题,用了队列等东西,发现还是挺难做的,索性直接看了刘汝佳的代码,发现还是刘汝佳厉害! 代码本身难度并不是很大,主要还是p=(p+n+d-1)%n+1;这一句有些难度,实际上经过自己的手动计算发现这一句真的是相当的正确,虽然无法准确的说明. 剩下的就是格式问题这个题很特别的只能用%3d的格式,我起初还不理解10前面为什么只有一个空格,还以为是题目打错了,没想到这就是要你%3d的意思. 我自己敲一遍的代码 #include <bits/stdc++.h> using namesp…
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(&qu…
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=69 13874119 133 The Dole Queue Accepted C++ 0.009 2014-07-13 02:44:49  The Dole Queue  In a serious attempt to downsize (reduce) the dole queue…
The Dole Queue Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit cid=1036#status//A/0" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" style="font-family:Verdana,Arial,sans…
题目链接: 啊哈哈,选我选我 思路是: 相当于模拟约瑟夫环,仅仅只是是从顺逆时针同一时候进行的,然后就是顺逆时针走能够编写一个函数,仅仅只是是走的方向的标志变量相反..还有就是为了(pos+flag+n-1)%n+1的妙用... 题目:  The Dole Queue  In a serious attempt to downsize (reduce) the dole queue, The New National Green Labour Rhinoceros Party has decid…
The Dole Queue Time limit 3000 ms Description In a serious attempt to downsize (reduce) the dole queue, The New National Green Labour Rhinoceros Party has decided on the following strategy. Every day all dole applicants will be placed in a large circ…
双向约瑟夫环. 数据规模只有20,模拟掉了.(其实公式我还是不太会推,有空得看看) 值得注意的是两个方向找值不是找到一个去掉一个,而是找到后同时去掉. 还有输出也很坑爹! 在这里不得不抱怨下Uva的oj,少了个s,少了个空行什么的都不会显示pe,就给个wa,让人还以为算法有问题.原本以为Uva没有pe,然后据说这边的输出空行如果不对的话就会显示pe... 代码: #include <cstdio> #include <cstring> const int maxn = 22; in…
类型:循环走步 #include <iostream> #include <sstream> #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <vector> #include <set> #include <cctype> #include <algorithm> #inc…