• uva133 The Dole Queue 循环队列模拟


    题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=69

    题目大意:

      1到n按照逆时针的顺序围成一个环,一个人逆时针从1开始数k个数字,另一个人顺时针从n开始数m个数字,每次两个人最终数到的数字输出,并且把他们从原来的环里面删除,如果两个人数到的数字不同,输出一对,如果相同,输出这个数字。不管重复上面的做法,直到n个数字全部被删除。

    题目思路:

      模拟题,代码弱,写了很久,写不出来,就是感觉比较麻烦,看了人家的代码,做法很好!http://blog.csdn.net/actoy/article/details/8747826

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstdlib>
     4 #include <cstring>
     5 #include <cctype>
     6 #include <stack>
     7 #include <queue>
     8 #include <deque>
     9 #include <map>
    10 #include <set>
    11 #include <vector>
    12 #include <cmath>
    13 #include <algorithm>
    14 #define lson l, m, rt<<1
    15 #define rson m+1, r, rt<<1|1
    16 using namespace std;
    17 typedef long long int LL;
    18 const int MAXN =  0x7fffffff;
    19 const int  MINN =  -0x7fffffff;
    20 const double eps = 1e-9;
    21 const int dir[8][2] = {{0,1},{1,0},{0,-1},{-1,0},{-1,1},
    22   {1,1},{1,-1},{-1,-1}};
    23 
    24 int main(void){
    25 #ifndef ONLINE_JUDGE
    26   freopen("uva133.in", "r", stdin);
    27 #endif
    28   int n, k, m, i, j, pos, pos1, cnt, f[30], tmp;
    29   map<int, bool> mymap;
    30   while (~scanf("%d%d%d", &n, &k, &m)) {
    31     if (n+k+m==0) break;
    32     memset(f, 0, sizeof(f));
    33     for (i = 1; i <= n; ++i) f[i] = i;
    34     pos = 0; pos1 = n + 1; cnt = 0;
    35     while (cnt < n) {
    36       tmp = 0;
    37       while (1) {
    38         if (f[pos] != 0) tmp++;
    39         if (pos > n) pos = 0;
    40         if (tmp == k) {
    41           printf("%3d", f[pos]);
    42           cnt++; break;
    43         }
    44         pos++;
    45       }
    46       tmp = 0;
    47       while (1) {
    48         if (f[pos1] != 0) tmp++;
    49         if (pos1 <= 0) pos1 = n + 1;
    50         if (tmp == m) {
    51           if (f[pos] != f[pos1]) {
    52             printf("%3d", f[pos1]);
    53             cnt++;
    54           }
    55           break;
    56         }
    57         pos1--;
    58       }
    59       f[pos] = f[pos1] = 0;
    60       if (cnt < n) printf(",");
    61     }
    62     printf("\n");
    63   }
    64 
    65   return 0;
    66 }

    这种题目,就是考的代码和问题实现的方式,方法不对可能实现起来超级麻烦……

    《夜莺》貌似第一次听这首曲子是4年前……

    很好听~

  • 相关阅读:
    WPS企业版序列号
    局域网远程
    win10 新增、删除、重命名文件需要刷新才更新的问题
    nginx配置文件参数详解
    TCP/IP协议明明白白
    iperf3
    华为交换机流量统计
    delphi 数据库技术沉浮录--谨献给成为历史的BDE
    在ubuntu 上使用wine 运行Delphi win32 应用
    kbmmw 中实现客户端自动更新
  • 原文地址:https://www.cnblogs.com/liuxueyang/p/3077406.html
Copyright © 2020-2023  润新知