UVa133.The Dole Queue】的更多相关文章

题目链接: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…
题目链接: 啊哈哈,选我选我 思路是: 相当于模拟约瑟夫环,仅仅只是是从顺逆时针同一时候进行的,然后就是顺逆时针走能够编写一个函数,仅仅只是是走的方向的标志变量相反..还有就是为了(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…
题意:约瑟夫问题,从两头双向删人.N个人逆时针1~N,从1开始逆时针每数k个人出列,同时从n开始顺时针每数m个人出列.若数到同一个人,则只有一个人出列.输出每次出列的人,用逗号可开每次的数据. 题解:模拟. 技巧:将顺时针逆时针的模拟合并为同一个函数. p1 = go(p1, 1, k);p2 = go(p2, -1, m); 循环处理: do p = (p + d + n - 1) % n + 1; while (a[p] == 0); (int p1 = n, p2 = 1;) 别忘了 a[…
题意: n个人围成个圆,从1到n,一个人从1数到k就让第k个人离场,了另一个人从n开始数,数到m就让第m个人下去,直到剩下最后一个人,并依次输出离场人的序号. 水题,直接上标程了 #include<stdio.h> #define maxn 25 int n, k, m, a[maxn]; // 逆时针走t步,步长是d(-1表示顺时针走),返回新位置 int go(int p, int d, int t) { while(t--) { do { p = (p+d+n-1) % n + 1; }…
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…
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…
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…
 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…
类型:循环走步 #include <iostream> #include <sstream> #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <vector> #include <set> #include <cctype> #include <algorithm> #inc…
题意:一个长度为N的循环队列,一个人从1号开始逆时针开始数数,第K个出列,一个人从第N个人开始顺时针数数,第M个出列,选到的两个人要同时出列(以不影响另一个人数数),选到同一个人就那个人出列. 思路:用数组来操作,详情见代码吧. #include <iostream> #include <stdio.h> #include <string> /* 用数组存储序号,从左到右依次为1~n. 逆时针相当于从左往右依次数,大于n再从1开始,用right作为指针. 顺时针相当于从…