CCF|火车购票|Java|80分
2024-08-26 12:18:24
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();
}
}
}
}
}
最新文章
- Python 字符串相加问题
- FlashFXP 破解代码
- css基本知识框架(转)
- International Conference in 2015
- asp.net mvc中包含webapi时,token失效产生302的解决方案
- 使用webdriver + phantomjs + pdfkit 生成PDF文件
- SQL Server 使用日志传送
- ubuntu安装python3
- 裸眼3D立体显示技术原理详解
- Spring MVC中注解 @ModelAttribute
- scp和pscp
- [Ext JS 4] contentEL,renderTo, applyTo 释义与区别
- Python学习中的一些小例子
- numpy初识
- 为什么 web 开发人员需要迁移到. NET Core, 并使用 ASP.NET Core MVC 构建 web 和 webservice/API
- NOIP2015提高组复赛B 子串
- unity中获取七天的日期
- 迭代器_iter_,生成器yeild,三元运算,列表解析(十三)
- 20. Spring Boot 默认、自定义数据源 、配置多个数据源 jdbcTemplate操作DB
- Netty入门(2) - 核心概念
热门文章
- Objective-C 中Socket常用转换机制(NSData,NSString,int,Uint8,Uint16,Uint32,byte[])
- poj 1274 The Perfect Stall 解题报告
- 【CQ18阶梯赛第二场】题解
- Linux命令排查线上问题常用的几个
- codeforces round 420 div2 补题 CF 821 A-E
- Eclipse全项目搜索指定文件&;字串
- UVa 1643 Angle and Squares (计算几何)
- 洛谷 - P1379 - 八数码难题 - bfs
- 洛谷 - P1004 - 方格取数 - 简单dp
- hdoj1789【贪心】