团体程序设计天梯赛 L1-049. 天梯赛座位分配(测试数据+不同方法)
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 数组:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <stdbool.h>
#include <set>
#include <vector>
#include <map>
#include <algorithm>
using namespace std; long f[][],g[],a[]; int main()
{
long n,i,j,num,c,pos;
scanf("%ld",&n);
for (i=;i<=n;i++)
{
scanf("%ld",&a[i]);
a[i]*=;
g[i]=;
} c=n;
num=;
pos=;
while (c>)
{
for (i=;i<=n;i++)
if (g[i]!=a[i])
{
num++;
g[i]++;
f[i][g[i]]=num;
if (g[i]==a[i])
c--;
pos=i;
}
}
if (c==)
{
for (j=;j<=n;j++)
if (g[j]!=a[j])
break;
if (pos!=j)
num++;
else
num+=;
g[j]++;
f[j][g[j]]=num;
for (i=g[j]+;i<=a[j];i++)
{
num+=;
g[j]++;
f[j][g[j]]=num;
}
}
for (i=;i<=n;i++)
{
printf("#%ld\n",i);
for (j=;j<=a[i];j++)
{
printf("%ld",f[i][j]);
if (j%==)
printf("\n");
else
printf(" ");
}
}
return ;
}
Way2 链环:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <stdbool.h>
#include <set>
#include <vector>
#include <map>
#include <algorithm>
using namespace std; //Á´»·
struct node
{
long a,b;
struct node *next,*pre;
}*q,*p,*r; long sch[][],g[]; int main()
{
long n,i,j,d,num=;
bool vis;
q=NULL;
scanf("%ld",&n);
for (i=;i<=n;i++)
{
scanf("%ld",&d);
p=(struct node *) malloc (sizeof(struct node));
p->a=i;
p->b=d*;
if (q==NULL)
q=p;
else
{
r->next=p;
p->pre=r;
}
r=p;
}
r->next=q;
q->pre=r; vis=false;
p=q;
while ()
{
if (p->a==p->next->a && vis)
num+=;
else
num++;
g[p->a]++;
sch[p->a][g[p->a]]=num;
p->b--;
vis=true;
if (p->b==)
{
if (p->a==p->next->a)
break;
else
{
p->pre->next=p->next;
p->next->pre=p->pre;
if (p->pre->a==p->next->a)
vis=false;
}
}
p=p->next;
}
for (i=;i<=n;i++)
{
printf("#%ld\n",i);
for (j=;j<=g[i];j++)
{
printf("%ld",sch[i][j]);
if (j%==)
printf("\n");
else
printf(" ");
}
}
return ;
}
Way3 vector:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <stdbool.h>
#include <set>
#include <vector>
#include <map>
#include <algorithm>
using namespace std; vector<pair<int,int> > f;
vector<int> sch[]; int main()
{
long n,a,num,pre,i;
vector<pair<int,int> >::iterator j;
vector<int>::iterator k;
scanf("%ld",&n);
for (i=;i<=n;i++)
{
scanf("%ld",&a);
f.push_back(make_pair(a*,i));
}
num=;
pre=-;
while (!f.empty())
{ for (j=f.begin();j!=f.end();j++)
{
if (pre==j->second)
num+=;
else
num++;
sch[j->second].push_back(num);
pre=j->second;
j->first--;
if (j->first==)
{
f.erase(j);
j--;
}
}
}
for (i=;i<=n;i++)
{
printf("#%ld\n",i);
for (k=sch[i].begin(),a=;k!=sch[i].end();k++,a++)
{
printf("%ld",*k);
if (a%==)
printf("\n");
else
printf(" ");
}
}
return ;
}
团体程序设计天梯赛 L1-049. 天梯赛座位分配(测试数据+不同方法)的更多相关文章
- PAT L1 049 天梯赛座位分配
天梯赛每年有大量参赛队员,要保证同一所学校的所有队员都不能相邻,分配座位就成为一件比较麻烦的事情.为此我们制定如下策略:假设某赛场有 N 所学校参赛,第 i 所学校有 M[i] 支队伍,每队 10 位 ...
- 团体程序设计天梯赛(CCCC) L3021 神坛 的一些错误做法(目前网上的方法没一个是对的) 和 一些想法
团体程序设计天梯赛代码.体现代码技巧,比赛技巧. https://github.com/congmingyige/cccc_code
- 团体程序设计天梯赛(CCCC) L3019 代码排版 方法与编译原理密切相关,只有一个测试点段错误
团体程序设计天梯赛代码.体现代码技巧,比赛技巧. https://github.com/congmingyige/cccc_code
- 团体程序设计天梯赛(CCCC) L3015 球队“食物链” 状态压缩
团体程序设计天梯赛代码.体现代码技巧,比赛技巧. https://github.com/congmingyige/cccc_code #include <cstdio> #include ...
- 团体程序设计天梯赛(CCCC) L3014 周游世界 BFS证明
团体程序设计天梯赛代码.体现代码技巧,比赛技巧. https://github.com/congmingyige/cccc_code
- 团体程序设计天梯赛(CCCC) L3013 非常弹的球 不同思路
团体程序设计天梯赛代码.体现代码技巧,比赛技巧. https://github.com/congmingyige/cccc_code
- 团体程序设计天梯赛(CCCC) L3012 水果忍者 上凸或下凹的证明
团体程序设计天梯赛代码.体现代码技巧,比赛技巧. https://github.com/congmingyige/cccc_code #include <cstdio> #include ...
- 团体程序设计天梯赛(CCCC) L3009 长城 方法证明
团体程序设计天梯赛代码.体现代码技巧,比赛技巧. https://github.com/congmingyige/cccc_code
- 树状数组+二分答案查询第k大的数 (团体程序设计天梯赛 L3-002. 堆栈)
前提是数的范围较小 1 数据范围:O(n) 2 查第k大的数i:log(n)(树状数组查询小于等于i的数目)*log(n)(二分找到i) 3 添加:log(n) (树状数组) 4 删除:log(n) ...
随机推荐
- hadoop之计数器和管道的mrunit测试
引言 hadoop的调试真心让人灰常恼火,而且从企业实际出发,集群的资源是有限的,不可能在集群上跑一遍又一遍根据log去调试代码,那么使用MRUnit编写测试单元,显得尤为重要.MRUnit中的Map ...
- PHP 伪协议
1.file:// file://用于访问本地文件系统,不受allow_url_fopen影响 <?php include($_GET['file']); ?> 2.http:// GET ...
- Centos7.2构建Python3.6开发环境
1.安装python3.6 1.这里使用一台全新的腾讯云主机,首先获取linux系统版本信息. [root@VM_46_121_centos ~]# cat /etc/redhat-release C ...
- Oracle和MySQL插入时获取主键
这里只写selectKey方法的 一,Oracle数据库中的写法 order="BEFORE"因为oracle中需要先从序列获取值,然后将值作为主键插入到数据库中 <sele ...
- Daily Scrum10 11.14
昨天的任务已经完成,但是我们在完成任务的过程中确实遇到了困难.昨天我们发现无法连接sqlserver的时候,给罗杰老师发了邮件.老师也给我们提出了建议,给我们提供了一些参考.所以今天大家都在研究如何解 ...
- [BUAA OO]第四次博客作业
一. 测试与正确性论证的区别 在最后一个单元的OO作业中,我们主要进行了代码的测试与正确性论证工作.这俩者在作业中的体现分别是junit单元测试以及jsf论述语言.这两者在java代码开 ...
- spring冲刺第二天
昨天查找了安卓开发的相关资料以及炸弹人游戏的资料. 由于今天课程比较多,只在晚上将安卓开发环境配置完成. 在安装软件时环境配置出现了问题,不过问过同学后成功解决.
- Beta Scrum Day 1 — 听说
听说
- Head First Java & 异常
- J2EE 13种技术规范
J2EE平台由一整套服务(种技术规范进行简单的描述(限于篇幅,这里只能进行简单的描述): 1.JDBC(Java Database Connectivity): JDBC API为访问不同的数据 ...