UVa 133 - The Dole Queue
2013-04-01 18:28
423 查看
双向循环队列。可以简化成单向队列。无非就是一个从左向右走K步输出。另一个从右往左走M步输出。如果两个走到同一位置则输出第一个。题不是很复杂。只不过输出的格式
很烦人。
思路:将所有数存在队列中。先遍历左边。指针front从0开始。如果front所指的数不为0,则tmp++。当tmp==K时。输出结果。tmp置为0.当指针front > Case时。指针在从最左边开始。将输出的位置置为0。从右遍历的同左遍历。注意的事当左边遍历已经输出的数。不能输出。
很烦人。
思路:将所有数存在队列中。先遍历左边。指针front从0开始。如果front所指的数不为0,则tmp++。当tmp==K时。输出结果。tmp置为0.当指针front > Case时。指针在从最左边开始。将输出的位置置为0。从右遍历的同左遍历。注意的事当左边遍历已经输出的数。不能输出。
// File Name: UVa133.cpp // Author: Toy // Created Time: 2013年04月01日 星期一 17时46分49秒 #include <iostream> #include <cstdio> #include <cstring> #include <vector> #include <cctype> #include <cmath> #include <string> #include <algorithm> #include <cstdlib> #include <iomanip> #include <list> #include <map> #include <set> #include <deque> #include <stack> #include <utility> #include <bitset> #define L(x) x << 1 #define R(x) x << 1 | 1 using namespace std; int queue[24], Case, k, m, front, rear, tmp1, tmp2, num; int main ( ) { while ( scanf ( "%d%d%d", &Case, &k, &m ) && Case + k + m ) { for ( int i = 1; i <= Case; ++i ) queue[i] = i; front = 0; rear = Case + 1; num = 1; while ( num <= Case ) { tmp1 = tmp2 = 0; while ( 1 ) { if ( queue[front] != 0 ) tmp1++; if ( front > Case ) front = 0; if ( tmp1 == k ) { printf ( "%3d", queue[front] ); num++; break; } front++; } while ( 1 ) { if ( queue[rear] != 0 ) tmp2++; if ( rear < 1 ) rear = Case + 1; if ( tmp2 == m ) { if ( queue[front] != queue[rear] ) { printf ( "%3d", queue[rear] ); num++; } break; } rear--; } queue[front] = 0; queue[rear] = 0; if ( num <= Case ) printf ( "," ); } printf ( "\n" ); } return 0; }
相关文章推荐
- uva 133 - The Dole Queue
- UVa-133 The Dole Queue
- UVA133-The Dole Queue
- 救济金发放(The Dole Queue, UVa 133)
- 【模拟】【环形数组】-UVA-133- The Dole Queue |java实现
- UVA133 The Dole Queue (模拟)
- UVA - 133 The Dole Queue 单纯模拟:1A
- Problem 014 —— UVa 133 - The Dole Queue
- 救济金发放 (The Dole QUEUE UVa 133)
- UVA133 The Dole Queue
- UVA - 133 The Dole Queue
- UVA - 133 The Dole Queue
- 救济金发放The Dole QueueUVA 133
- UVa 133 - The Dole Queue
- UVa133 The Dole Queue
- UVa133 - The Dole Queue
- The Dole Queue UVA - 133
- UVa133 - The Dole Queue
- uva133 The Dole Queue 循环队列模拟
- The Dole Queue(UVA 133)