团体程序设计天梯赛 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) ...
随机推荐
- pytorch 如何使用tensorboard实时查看曲线---- tensorboardX简介
用惯了tensorflow的小伙伴肯定都用过tensorboard工具吧.虽然Facebook也推出了visdom,但是在一次不小心误触clear之后,我放弃了这个工具(页面的一个clear按钮我本来 ...
- IPC_Binder_java_2
title: IPC_Binder_java_2 date: 2017-07-04 14:47:55 tags: [IPC,Binder] categories: [Mobile,Android] - ...
- NodeJS http模块
Node.js提供了http模块,用于搭建HTTP服务端和客户端. 创建Web服务器 /** * node-http 服务端 */ let http = require('http'); let ur ...
- JS进阶系列之闭包
刚刚总结完作用域链,我觉得很有必要马上对闭包总结一下,因为,之前也写过自己对闭包的理解,那时候只知道,闭包就是可以访问别的函数变量的函数,就是在函数里面的函数就叫做闭包,可是并没有深入探究,为什么,可 ...
- 互评beta版本 - hello word!【空天猎】
基于NABCD评论作品 1.Need需求:市面上同类型的手机及PC端飞行射击类游戏有很多,所以从需求方面来说,这款游戏的潜在客户非常有局限性.近些年较火的飞行射击类游戏,例如腾讯14年发行的<全 ...
- No.1011_第八次团队会议
罗老师和Bigman助教: 一直以来没看博客页面,我们的博客负责人不是没写博客,而是不小心把博客发到草稿上了.. 请您再次看一下我们的博客,并批评指正! 今天大家的情绪依旧很低落,离第一轮迭代完成距离 ...
- 45度炸队Alpha冲刺博客集
博客集如下: Alpha冲刺Day1:第一天冲刺记录 Alpha冲刺Day2:第二天冲刺记录 Alpha冲刺Day3:第三天冲刺记录 Alpha冲刺Day4:第四天冲刺记录 Alpha冲刺Day5:第 ...
- 第二章 Socket用法详解
构造Socket Socket构造方法如下: Socket() //Creates an unconnected socket, with the system-default type of Soc ...
- 基于windowsphone7的控制ppt播放
最近突然想起了一个学长的一个利用手机控制ppt播放的一个创意,并想将其在windows phone7上实现一下. 经过几天的努力已经可以控制ppt的播放,暂停,上一张,下一张了,并且电脑会将当前ppt ...
- 个人作业week3案例分析
调研产品:博客园 第一部分 调研和评测 1.bug 1.不同种类浏览器的支持存在差异 bug描述:在不同浏览器下,部分博客内容显示的格式有明显不同 可尝试用下面两种不同的浏览器打开这个博客网址:htt ...