Data:

/*
3
3 2 1
#1
1 4 7 10 13 16 19 22 25 28
31 33 35 37 39 41 43 45 47 49
51 53 55 57 59 61 63 65 67 69
#2
2 5 8 11 14 17 20 23 26 29
32 34 36 38 40 42 44 46 48 50
#3
3 6 9 12 15 18 21 24 27 30

2
1 2
#1
1 3 5 7 9 11 13 15 17 19
#2
2 4 6 8 10 12 14 16 18 20
22 24 26 28 30 32 34 36 38 40

1
3
#1
1 3 5 7 9 11 13 15 17 19
21 23 25 27 29 31 33 35 37 39
41 43 45 47 49 51 53 55 57 59
*/

Way1 数组:

  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include <cstring>
  4. #include <cmath>
  5. #include <stdbool.h>
  6. #include <set>
  7. #include <vector>
  8. #include <map>
  9. #include <algorithm>
  10. using namespace std;
  11.  
  12. long f[][],g[],a[];
  13.  
  14. int main()
  15. {
  16. long n,i,j,num,c,pos;
  17. scanf("%ld",&n);
  18. for (i=;i<=n;i++)
  19. {
  20. scanf("%ld",&a[i]);
  21. a[i]*=;
  22. g[i]=;
  23. }
  24.  
  25. c=n;
  26. num=;
  27. pos=;
  28. while (c>)
  29. {
  30. for (i=;i<=n;i++)
  31. if (g[i]!=a[i])
  32. {
  33. num++;
  34. g[i]++;
  35. f[i][g[i]]=num;
  36. if (g[i]==a[i])
  37. c--;
  38. pos=i;
  39. }
  40. }
  41. if (c==)
  42. {
  43. for (j=;j<=n;j++)
  44. if (g[j]!=a[j])
  45. break;
  46. if (pos!=j)
  47. num++;
  48. else
  49. num+=;
  50. g[j]++;
  51. f[j][g[j]]=num;
  52. for (i=g[j]+;i<=a[j];i++)
  53. {
  54. num+=;
  55. g[j]++;
  56. f[j][g[j]]=num;
  57. }
  58. }
  59. for (i=;i<=n;i++)
  60. {
  61. printf("#%ld\n",i);
  62. for (j=;j<=a[i];j++)
  63. {
  64. printf("%ld",f[i][j]);
  65. if (j%==)
  66. printf("\n");
  67. else
  68. printf(" ");
  69. }
  70. }
  71. return ;
  72. }

Way2 链环:

  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include <cstring>
  4. #include <cmath>
  5. #include <stdbool.h>
  6. #include <set>
  7. #include <vector>
  8. #include <map>
  9. #include <algorithm>
  10. using namespace std;
  11.  
  12. //Á´»·
  13. struct node
  14. {
  15. long a,b;
  16. struct node *next,*pre;
  17. }*q,*p,*r;
  18.  
  19. long sch[][],g[];
  20.  
  21. int main()
  22. {
  23. long n,i,j,d,num=;
  24. bool vis;
  25. q=NULL;
  26. scanf("%ld",&n);
  27. for (i=;i<=n;i++)
  28. {
  29. scanf("%ld",&d);
  30. p=(struct node *) malloc (sizeof(struct node));
  31. p->a=i;
  32. p->b=d*;
  33. if (q==NULL)
  34. q=p;
  35. else
  36. {
  37. r->next=p;
  38. p->pre=r;
  39. }
  40. r=p;
  41. }
  42. r->next=q;
  43. q->pre=r;
  44.  
  45. vis=false;
  46. p=q;
  47. while ()
  48. {
  49. if (p->a==p->next->a && vis)
  50. num+=;
  51. else
  52. num++;
  53. g[p->a]++;
  54. sch[p->a][g[p->a]]=num;
  55. p->b--;
  56. vis=true;
  57. if (p->b==)
  58. {
  59. if (p->a==p->next->a)
  60. break;
  61. else
  62. {
  63. p->pre->next=p->next;
  64. p->next->pre=p->pre;
  65. if (p->pre->a==p->next->a)
  66. vis=false;
  67. }
  68. }
  69. p=p->next;
  70. }
  71. for (i=;i<=n;i++)
  72. {
  73. printf("#%ld\n",i);
  74. for (j=;j<=g[i];j++)
  75. {
  76. printf("%ld",sch[i][j]);
  77. if (j%==)
  78. printf("\n");
  79. else
  80. printf(" ");
  81. }
  82. }
  83. return ;
  84. }

Way3 vector:

  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include <cstring>
  4. #include <cmath>
  5. #include <stdbool.h>
  6. #include <set>
  7. #include <vector>
  8. #include <map>
  9. #include <algorithm>
  10. using namespace std;
  11.  
  12. vector<pair<int,int> > f;
  13. vector<int> sch[];
  14.  
  15. int main()
  16. {
  17. long n,a,num,pre,i;
  18. vector<pair<int,int> >::iterator j;
  19. vector<int>::iterator k;
  20. scanf("%ld",&n);
  21. for (i=;i<=n;i++)
  22. {
  23. scanf("%ld",&a);
  24. f.push_back(make_pair(a*,i));
  25. }
  26. num=;
  27. pre=-;
  28. while (!f.empty())
  29. {
  30.  
  31. for (j=f.begin();j!=f.end();j++)
  32. {
  33. if (pre==j->second)
  34. num+=;
  35. else
  36. num++;
  37. sch[j->second].push_back(num);
  38. pre=j->second;
  39. j->first--;
  40. if (j->first==)
  41. {
  42. f.erase(j);
  43. j--;
  44. }
  45. }
  46. }
  47. for (i=;i<=n;i++)
  48. {
  49. printf("#%ld\n",i);
  50. for (k=sch[i].begin(),a=;k!=sch[i].end();k++,a++)
  51. {
  52. printf("%ld",*k);
  53. if (a%==)
  54. printf("\n");
  55. else
  56. printf(" ");
  57. }
  58. }
  59. return ;
  60. }

团体程序设计天梯赛 L1-049. 天梯赛座位分配(测试数据+不同方法)的更多相关文章

  1. PAT L1 049 天梯赛座位分配

    天梯赛每年有大量参赛队员,要保证同一所学校的所有队员都不能相邻,分配座位就成为一件比较麻烦的事情.为此我们制定如下策略:假设某赛场有 N 所学校参赛,第 i 所学校有 M[i] 支队伍,每队 10 位 ...

  2. 团体程序设计天梯赛(CCCC) L3021 神坛 的一些错误做法(目前网上的方法没一个是对的) 和 一些想法

    团体程序设计天梯赛代码.体现代码技巧,比赛技巧.  https://github.com/congmingyige/cccc_code

  3. 团体程序设计天梯赛(CCCC) L3019 代码排版 方法与编译原理密切相关,只有一个测试点段错误

    团体程序设计天梯赛代码.体现代码技巧,比赛技巧.  https://github.com/congmingyige/cccc_code

  4. 团体程序设计天梯赛(CCCC) L3015 球队“食物链” 状态压缩

    团体程序设计天梯赛代码.体现代码技巧,比赛技巧.  https://github.com/congmingyige/cccc_code #include <cstdio> #include ...

  5. 团体程序设计天梯赛(CCCC) L3014 周游世界 BFS证明

    团体程序设计天梯赛代码.体现代码技巧,比赛技巧.  https://github.com/congmingyige/cccc_code

  6. 团体程序设计天梯赛(CCCC) L3013 非常弹的球 不同思路

    团体程序设计天梯赛代码.体现代码技巧,比赛技巧.  https://github.com/congmingyige/cccc_code

  7. 团体程序设计天梯赛(CCCC) L3012 水果忍者 上凸或下凹的证明

    团体程序设计天梯赛代码.体现代码技巧,比赛技巧.  https://github.com/congmingyige/cccc_code #include <cstdio> #include ...

  8. 团体程序设计天梯赛(CCCC) L3009 长城 方法证明

    团体程序设计天梯赛代码.体现代码技巧,比赛技巧.  https://github.com/congmingyige/cccc_code

  9. 树状数组+二分答案查询第k大的数 (团体程序设计天梯赛 L3-002. 堆栈)

    前提是数的范围较小 1 数据范围:O(n) 2 查第k大的数i:log(n)(树状数组查询小于等于i的数目)*log(n)(二分找到i) 3 添加:log(n) (树状数组) 4 删除:log(n) ...

随机推荐

  1. 04-matplotlib-柱形图

    import numpy as np import matplotlib.pyplot as plt # 柱形图 # 例一 N =5 y = [15,28,10,30,25] index = np.a ...

  2. ossec兼容的操作系统

    OSSEC兼容以下操作系统和日志格式 操作系统 以下操作系统可安装OSSEC代理 l  GNU/Linux (all distributions, including RHEL, Ubuntu, Sl ...

  3. Annotation 使用备忘2

    title: Annotation 使用备忘 date: 2018-01-02 20:48:43 tags: [Annotation] categories: [Programming,Java] - ...

  4. groupadd命令详解

    基础命令学习目录首页 原文链接:https://wtj6891.iteye.com/blog/2096076 groupadd创建组群 使用groupadd命令可以在系统中创建组群账户 语法: gro ...

  5. Python20 - Day09

    python并发编程之多线程理论 1.什么是线程? 进程只是用来把资源集中到一起(进程是一个资源单位,或者说资源集合),而线程才是cpu上的执行单位. 多线程(多个控制线程)的概念是,在一个进程中存在 ...

  6. FFmpeg简单转码程序--视频剪辑

    学习了雷神的文章,慕斯人分享精神,感其英年而逝,不胜唏嘘.他有分享一个转码程序<最简单的基于FFMPEG的转码程序>其中使用了filter(参考了ffmpeg.c中的流程),他曾说想再编写 ...

  7. web05-CounterServlet

    电影网站:www.aikan66.com 项目网站:www.aikan66.com 游戏网站:www.aikan66.com 图片网站:www.aikan66.com 书籍网站:www.aikan66 ...

  8. 除了C语言,C++······竟然还有Z语言?

    只能说自己见识短,头一次听说Z语言.先普及一下吧: Z语言是由牛津大学程序设计研究小组开发的一种形式语言,它是一种以一阶谓词演算为主要理论基础的规约语言,是一种功能性语言.Z语言是将事物的状态和行为用 ...

  9. vs2013+python+ cocos2d-x-3.3rc0环境搭建

    1.vs2013安装一路next,安装即可,时间1~2个小时 2.解压cocos2d-x-3.3rc0   build文件夹里会有名为  cocos2d-win32.vc2012的sln文件  打开  ...

  10. 谈对“Git”的认识与理解

    自诞生于2005年以来,Git日臻完善,在高度易用的同时,仍然保留着初期设定的目标.它的速度飞快,及其适合管理大项目,它还有着令人难以置信的非线性分支管理系统,可以应付各种复杂的项目开发需求.接着说说 ...