团体程序设计天梯赛 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) ...
随机推荐
- 关于注册github
- Gogoing 场景调研(补)
一.典型用户 蜗居在学校的大学生 二.场景描述 编号 用户故事 故事价值 (点数) 1 作为一名大学生,只知道学习 2 经常打游戏而无所事事的大学生 1.背景 (1)典型用户:张晨建 (2)用户的需求 ...
- WebService有什么用?
入门之前先简单介绍下WCF.在用WebService做开发时,很多人都不知道WCF和WebService之间的关系.实际上WCF包含了WebService,这是一个很强悍的通信技术应用框架.微软把.N ...
- java集合LinkedList
基于jdk_1.8.0 关于List,主要是有序的可重复的数据结构.jdk主要实现类有ArrayList(底层使用数组).LinkedList(底层使用双向链表) LinkedList: (一)继承关 ...
- 6/8 sprint2 看板和燃尽图的更新
- 词频统计的java实现方法——第一次改进
需求概要 原需求 1.读取文件,文件内包可含英文字符,及常见标点,空格级换行符. 2.统计英文单词在本文件的出现次数 3.将统计结果排序 4.显示排序结果 新需求: 1.小文件输入. 为表明程序能跑 ...
- [转贴] IPSEC From 知乎
作者:埃文科技链接:https://zhuanlan.zhihu.com/p/44874772来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 认识IPSec IPSec ...
- .NET Socket 简单入门
说到Socket,想必大家都或多或少有所涉及,从最初的计算机网络课程,讲述了tcp协议,而Socket就是对协议的进一步封装,使我们开发人员能够更加容易轻松的进行软件之间的通信. 这个星期刚好接受一个 ...
- Java容器深入浅出之PriorityQueue、ArrayDeque和LinkedList
Queue用于模拟一种FIFO(first in first out)的队列结构.一般来说,典型的队列结构不允许随机访问队列中的元素.队列包含的方法为: 1. 入队 void add(Object o ...
- 【译】关于vertical-align你应知道的一切
原文地址:Vertical-Align: All You Need To Know 通常我们需要垂直对齐并排的元素. CSS提供了一些可实现的方法:有时我用浮动float来解决,有时用position ...