import java.util.*;

public class Main

{

public static void main(String[] args)

{

Scanner in = new Scanner(System.in);

int n = in.nextInt();

int[][] ints = new int[20][5];

    for (int i = 0; i < 20; i++)
{
Arrays.fill(ints[i], 0);
} int si = 0;
for (int j = 0; j < n; j++)
{
int site = in.nextInt(); for (int i = 0; i < 20; i++)
{ if (si <= 19)
{
if (site <= foundPlace(ints[i]))
{
setPlace(ints[i], i, site);
if (si <= i)
{
si++;
}
break;
}
}
else if (si > 19)
{
if (site <= foundPlace(ints[i]))
{
setPlace(ints[i], i, site);
return;
}
else if (foundPlace(ints[i]) < site)
{
int s = foundPlace(ints[i]);
setPlace(ints[i], i, foundPlace(ints[i]));
site -= s; }
}
}
}
} /**
* @param ints
* @return 空位置数目
*/
private static int foundPlace(int[] ints)
{
int s = 0;
for (int i = 4; i >= 0 && ints[i] == 0; i--)
{
s++;
}
return s;
} /**
* @param ints
* @return
*/
private static void setPlace(int[] ints, int p, int q)
{
int qq = 0;
for (int i = 0; i < 5; i++)
{
if (ints[i] == 0 && qq < q)
{
ints[i] = p * 5 + i + 1;
qq++; System.out.print(ints[i]);
if (qq != q)
{
System.out.print(" ");
}
else if (qq == q)
{
System.out.println();
}
}
}
}

}

CCF|火车购票|Java|80分的更多相关文章

  1. CCF201609-2 火车购票 java(100分)

    试题编号: 201609-2 试题名称: 火车购票 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 请实现一个铁路购票系统的简单座位分配算法,来处理一节车厢的座位分配. 假设一 ...

  2. ccf 火车购票

    import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Main2 { pu ...

  3. 201609-2 火车购票 Java

    思路待补充 import java.util.Scanner; class Main{ public static void main(String[] args) { //100个座位 int[] ...

  4. 【刷题笔记】火车购票-----java方案

    问题描述请实现一个铁路购票系统的简单座位分配算法,来处理一节车厢的座位分配. 假设一节车厢有20排.每一排5个座位.为方便起见,我们用1到100来给所有的座位编号,第一排是1到5号,第二排是6到10号 ...

  5. CCF(URL映射:80分):字符串处理+模拟

    URL映射 CCF201803-3 #include<iostream> #include<cstdio> #include<cstring> #include&l ...

  6. CCF(消息传递口:80分):字符串相关+队列

    消息传递口 201903-4 本题主要是利用队列进行模拟,因为一开始我没有注意到要按照顺序,所以一开始的解法错误. #include<iostream> #include<algor ...

  7. url映射 ccf (Java正则表达式80分解法)

    问题描述 试题编号: 201803-3 试题名称: URL映射 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 URL 映射是诸如 Django.Ruby on Rails 等 ...

  8. CCF CSP 201609-2 火车购票

    题目链接:http://118.190.20.162/view.page?gpid=T46 问题描述 请实现一个铁路购票系统的简单座位分配算法,来处理一节车厢的座位分配. 假设一节车厢有20排.每一排 ...

  9. CCF 2016-09-2 火车购票

    CCF 2016-09-2 火车购票 题目 问题描述 请实现一个铁路购票系统的简单座位分配算法,来处理一节车厢的座位分配. 假设一节车厢有20排.每一排5个座位.为方便起见,我们用1到100来给所有的 ...

随机推荐

  1. 【转载】Java中StringTokenizer类的作用

    StringTokenizer是一个用来分隔String的应用类,相当于VB的split函数.1.构造函数public StringTokenizer(String str)public String ...

  2. cf 620C Pearls in a Row(贪心)

    d.有一串数字,要把这些数字分成若干连续的段,每段必须至少包含2个相同的数字,怎么分才能分的段数最多? 比如 是1 2 1 3 1 2 1 那么 答案是 21 34 7 即最多分在2段,第一段是1~3 ...

  3. POJ-3352 Redundant Paths

    In order to get from one of the F (1 <= F <= 5,000) grazing fields (which are numbered 1..F) t ...

  4. 网站页面打开浏览器table中显示图片

    就类似博客园这种:

  5. 书写优雅的shell脚本(插曲)- /proc

    1. /proc目录 Linux 内核提供了一种通过 /proc 文件系统,在运行时访问内核内部数据结构.改变内核设置的机制.proc文件系统是一个伪文件系统,它只存在内存当中,而不占用外存空间.它以 ...

  6. codeforces 669D D. Little Artem and Dance(乱搞题)

    题目链接: D. Little Artem and Dance time limit per test 2 seconds memory limit per test 256 megabytes in ...

  7. [Selenium] common functions comparison

    1.Wait for element  in default time or self defined time When the element need some time to be prese ...

  8. Linux 系统开机启动项清理

    一般情况下,常规用途的 Linux 发行版在开机启动时拉起各种相关服务进程,包括许多你可能无需使用的服务,例如蓝牙bluetooth.Avahi. 调制解调管理器ModemManager.ppp-dn ...

  9. 【转】 IntelliJ IDEA 中 Project 和 Module 的概念及区别

    原文地址:https://blog.csdn.net/qq_35246620/article/details/65448689 在 IntelliJ IDEA 中,没有类似于 Eclipse 工作空间 ...

  10. WaveNet: 原始音频生成模型

    官方博客 WaveNet: A Generative Model for Raw Audio paper地址:paper Abstract WaveNet是probabilistic and auto ...